<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-pragma">{-# LANGUAGE Trustworthy #-}</span><span>
</span><span id="line-2"></span><span class="hs-pragma">{-# LANGUAGE CPP
           , NoImplicitPrelude
           , RecordWildCards
           , BangPatterns
           , NondecreasingIndentation
           , MagicHash
  #-}</span><span>
</span><span id="line-9"></span><span class="hs-pragma">{-# OPTIONS_GHC -Wno-unused-matches #-}</span><span>
</span><span id="line-10"></span><span class="hs-pragma">{-# OPTIONS_HADDOCK not-home #-}</span><span>
</span><span id="line-11"></span><span>
</span><span id="line-12"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-13"></span><span class="hs-comment">-- |</span><span>
</span><span id="line-14"></span><span class="hs-comment">-- Module      :  GHC.IO.Text</span><span>
</span><span id="line-15"></span><span class="hs-comment">-- Copyright   :  (c) The University of Glasgow, 1992-2008</span><span>
</span><span id="line-16"></span><span class="hs-comment">-- License     :  see libraries/base/LICENSE</span><span>
</span><span id="line-17"></span><span class="hs-comment">--</span><span>
</span><span id="line-18"></span><span class="hs-comment">-- Maintainer  :  libraries@haskell.org</span><span>
</span><span id="line-19"></span><span class="hs-comment">-- Stability   :  internal</span><span>
</span><span id="line-20"></span><span class="hs-comment">-- Portability :  non-portable</span><span>
</span><span id="line-21"></span><span class="hs-comment">--</span><span>
</span><span id="line-22"></span><span class="hs-comment">-- String I\/O functions</span><span>
</span><span id="line-23"></span><span class="hs-comment">--</span><span>
</span><span id="line-24"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-25"></span><span>
</span><span id="line-26"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.IO.Handle.Text</span><span> </span><span class="hs-special">(</span><span>
</span><span id="line-27"></span><span>        </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hWaitForInput"><span class="hs-identifier">hWaitForInput</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetChar"><span class="hs-identifier">hGetChar</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetLine"><span class="hs-identifier">hGetLine</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetContents"><span class="hs-identifier">hGetContents</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutChar"><span class="hs-identifier">hPutChar</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutStr"><span class="hs-identifier">hPutStr</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-28"></span><span>        </span><span class="annot"><a href="GHC.IO.Handle.Text.html#commitBuffer%27"><span class="hs-identifier">commitBuffer'</span></a></span><span class="hs-special">,</span><span>       </span><span class="hs-comment">-- hack, see below</span><span>
</span><span id="line-29"></span><span>        </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetBuf"><span class="hs-identifier">hGetBuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetBufSome"><span class="hs-identifier">hGetBufSome</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetBufNonBlocking"><span class="hs-identifier">hGetBufNonBlocking</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutBuf"><span class="hs-identifier">hPutBuf</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutBufNonBlocking"><span class="hs-identifier">hPutBufNonBlocking</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-30"></span><span>        </span><span class="annot"><a href="GHC.IO.Handle.Text.html#memcpy"><span class="hs-identifier">memcpy</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutStrLn"><span class="hs-identifier">hPutStrLn</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetContents%27"><span class="hs-identifier">hGetContents'</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-31"></span><span>    </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-32"></span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.html"><span class="hs-identifier">GHC.IO</span></a></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html"><span class="hs-identifier">GHC.IO.Buffer</span></a></span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.IO.BufferedIO.html"><span class="hs-identifier">GHC.IO.BufferedIO</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Buffered</span></span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Exception.html"><span class="hs-identifier">GHC.IO.Exception</span></a></span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Exception.html"><span class="hs-identifier">GHC.Exception</span></a></span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html"><span class="hs-identifier">GHC.IO.Handle.Types</span></a></span><span>
</span><span id="line-39"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Internals.html"><span class="hs-identifier">GHC.IO.Handle.Internals</span></a></span><span>
</span><span id="line-40"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.IO.Device.html"><span class="hs-identifier">GHC.IO.Device</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">IODevice</span></span><span>
</span><span id="line-41"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="GHC.IO.Device.html"><span class="hs-identifier">GHC.IO.Device</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">RawIO</span></span><span>
</span><span id="line-42"></span><span>
</span><span id="line-43"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.html"><span class="hs-identifier">Foreign</span></a></span><span>
</span><span id="line-44"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Foreign.C.html"><span class="hs-identifier">Foreign.C</span></a></span><span>
</span><span id="line-45"></span><span>
</span><span id="line-46"></span><span class="hs-keyword">import</span><span> </span><span class="hs-keyword">qualified</span><span> </span><span class="annot"><a href="Control.Exception.html"><span class="hs-identifier">Control.Exception</span></a></span><span> </span><span class="hs-keyword">as</span><span> </span><span class="annot"><span class="hs-identifier">Exception</span></span><span>
</span><span id="line-47"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="System.IO.Error.html"><span class="hs-identifier">System.IO.Error</span></a></span><span>
</span><span id="line-48"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Either.html"><span class="hs-identifier">Data.Either</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier">Either</span></a></span><span class="hs-special">(</span><span class="hs-glyph">..</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-49"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="Data.Maybe.html"><span class="hs-identifier">Data.Maybe</span></a></span><span>
</span><span id="line-50"></span><span>
</span><span id="line-51"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.IORef.html"><span class="hs-identifier">GHC.IORef</span></a></span><span>
</span><span id="line-52"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Base.html"><span class="hs-identifier">GHC.Base</span></a></span><span>
</span><span id="line-53"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Real.html"><span class="hs-identifier">GHC.Real</span></a></span><span>
</span><span id="line-54"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Num.html"><span class="hs-identifier">GHC.Num</span></a></span><span>
</span><span id="line-55"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Show.html"><span class="hs-identifier">GHC.Show</span></a></span><span>
</span><span id="line-56"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.List.html"><span class="hs-identifier">GHC.List</span></a></span><span>
</span><span id="line-57"></span><span>
</span><span id="line-58"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-59"></span><span class="hs-comment">-- Simple input operations</span><span>
</span><span id="line-60"></span><span>
</span><span id="line-61"></span><span class="hs-comment">-- If hWaitForInput finds anything in the Handle's buffer, it</span><span>
</span><span id="line-62"></span><span class="hs-comment">-- immediately returns.  If not, it tries to read from the underlying</span><span>
</span><span id="line-63"></span><span class="hs-comment">-- OS handle. Notice that for buffered Handles connected to terminals</span><span>
</span><span id="line-64"></span><span class="hs-comment">-- this means waiting until a complete line is available.</span><span>
</span><span id="line-65"></span><span>
</span><span id="line-66"></span><span class="hs-comment">-- | Computation 'hWaitForInput' @hdl t@</span><span>
</span><span id="line-67"></span><span class="hs-comment">-- waits until input is available on handle @hdl@.</span><span>
</span><span id="line-68"></span><span class="hs-comment">-- It returns 'True' as soon as input is available on @hdl@,</span><span>
</span><span id="line-69"></span><span class="hs-comment">-- or 'False' if no input is available within @t@ milliseconds.  Note that</span><span>
</span><span id="line-70"></span><span class="hs-comment">-- 'hWaitForInput' waits until one or more full /characters/ are available,</span><span>
</span><span id="line-71"></span><span class="hs-comment">-- which means that it needs to do decoding, and hence may fail</span><span>
</span><span id="line-72"></span><span class="hs-comment">-- with a decoding error.</span><span>
</span><span id="line-73"></span><span class="hs-comment">--</span><span>
</span><span id="line-74"></span><span class="hs-comment">-- If @t@ is less than zero, then @hWaitForInput@ waits indefinitely.</span><span>
</span><span id="line-75"></span><span class="hs-comment">--</span><span>
</span><span id="line-76"></span><span class="hs-comment">-- This operation may fail with:</span><span>
</span><span id="line-77"></span><span class="hs-comment">--</span><span>
</span><span id="line-78"></span><span class="hs-comment">--  * 'isEOFError' if the end of file has been reached.</span><span>
</span><span id="line-79"></span><span class="hs-comment">--</span><span>
</span><span id="line-80"></span><span class="hs-comment">--  * a decoding error, if the input begins with an invalid byte sequence</span><span>
</span><span id="line-81"></span><span class="hs-comment">--    in this Handle's encoding.</span><span>
</span><span id="line-82"></span><span class="hs-comment">--</span><span>
</span><span id="line-83"></span><span class="hs-comment">-- NOTE for GHC users: unless you use the @-threaded@ flag,</span><span>
</span><span id="line-84"></span><span class="hs-comment">-- @hWaitForInput hdl t@ where @t &gt;= 0@ will block all other Haskell</span><span>
</span><span id="line-85"></span><span class="hs-comment">-- threads for the duration of the call.  It behaves like a</span><span>
</span><span id="line-86"></span><span class="hs-comment">-- @safe@ foreign call in this respect.</span><span>
</span><span id="line-87"></span><span class="hs-comment">--</span><span>
</span><span id="line-88"></span><span>
</span><span id="line-89"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hWaitForInput"><span class="hs-identifier hs-type">hWaitForInput</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>
</span><span id="line-90"></span><span id="hWaitForInput"><span class="annot"><span class="annottext">hWaitForInput :: Handle -&gt; Int -&gt; IO Bool
</span><a href="GHC.IO.Handle.Text.html#hWaitForInput"><span class="hs-identifier hs-var hs-var">hWaitForInput</span></a></span></span><span> </span><span id="local-6989586621679557825"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557825"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679557824"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557824"><span class="hs-identifier hs-var">msecs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-91"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; Handle -&gt; (Handle__ -&gt; IO Bool) -&gt; IO Bool
forall a. String -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle_"><span class="hs-identifier hs-var">wantReadableHandle_</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hWaitForInput&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557825"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO Bool) -&gt; IO Bool)
-&gt; (Handle__ -&gt; IO Bool) -&gt; IO Bool
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679557822"><span class="annot"><span class="annottext">handle_ :: Handle__
</span><a href="#local-6989586621679557822"><span class="hs-identifier hs-var">handle_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557789"><span id="local-6989586621679557790"><span id="local-6989586621679557791"><span id="local-6989586621679557792"><span id="local-6989586621679557793"><span id="local-6989586621679557794"><span id="local-6989586621679557795"><span id="local-6989586621679557796"><span id="local-6989586621679557797"><span id="local-6989586621679557798"><span id="local-6989586621679557799"><span id="local-6989586621679557800"><span id="local-6989586621679557801"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
</span><a href="GHC.IO.Handle.Types.html#haType"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-92"></span><span>  </span><span id="local-6989586621679557775"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557775"><span class="hs-identifier hs-var">cbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557796"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-93"></span><span>
</span><span id="line-94"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557775"><span class="hs-identifier hs-var">cbuf</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-95"></span><span>
</span><span id="line-96"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557824"><span class="hs-identifier hs-var">msecs</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-97"></span><span>        </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679557770"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557770"><span class="hs-identifier hs-var">cbuf'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#readTextDevice"><span class="hs-identifier hs-var">readTextDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557822"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557775"><span class="hs-identifier hs-var">cbuf</span></a></span><span>
</span><span id="line-98"></span><span>                </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557796"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557770"><span class="hs-identifier hs-var">cbuf'</span></a></span><span>
</span><span id="line-99"></span><span>                </span><span class="annot"><span class="annottext">Bool -&gt; IO Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-100"></span><span>        </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-101"></span><span>               </span><span class="hs-comment">-- there might be bytes in the byte buffer waiting to be decoded</span><span>
</span><span id="line-102"></span><span>               </span><span id="local-6989586621679557767"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557767"><span class="hs-identifier hs-var">cbuf'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#decodeByteBuf"><span class="hs-identifier hs-var">decodeByteBuf</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557822"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557775"><span class="hs-identifier hs-var">cbuf</span></a></span><span>
</span><span id="line-103"></span><span>               </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557796"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557767"><span class="hs-identifier hs-var">cbuf'</span></a></span><span>
</span><span id="line-104"></span><span>
</span><span id="line-105"></span><span>               </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557767"><span class="hs-identifier hs-var">cbuf'</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-106"></span><span>
</span><span id="line-107"></span><span>                </span><span id="local-6989586621679557765"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557765"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Bool -&gt; Int -&gt; IO Bool
forall a. IODevice a =&gt; a -&gt; Bool -&gt; Int -&gt; IO Bool
</span><a href="GHC.IO.Device.html#ready"><span class="hs-identifier hs-var">IODevice.ready</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679557801"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-comment">{-read-}</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557824"><span class="hs-identifier hs-var">msecs</span></a></span><span>
</span><span id="line-108"></span><span>                </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557765"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-comment">-- Call hLookAhead' to throw an EOF</span><span>
</span><span id="line-109"></span><span>                             </span><span class="hs-comment">-- exception if appropriate</span><span>
</span><span id="line-110"></span><span>                             </span><span class="annot"><span class="annottext">Char
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO Char
</span><a href="GHC.IO.Handle.Internals.html#hLookAhead_"><span class="hs-identifier hs-var">hLookAhead_</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557822"><span class="hs-identifier hs-var">handle_</span></a></span><span>
</span><span id="line-111"></span><span>                             </span><span class="annot"><span class="annottext">Bool -&gt; IO Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-112"></span><span>                     </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; IO Bool
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-113"></span><span>                </span><span class="hs-comment">-- XXX we should only return when there are full characters</span><span>
</span><span id="line-114"></span><span>                </span><span class="hs-comment">-- not when there are only bytes.  That would mean looping</span><span>
</span><span id="line-115"></span><span>                </span><span class="hs-comment">-- and re-running IODevice.ready if we don't have any full</span><span>
</span><span id="line-116"></span><span>                </span><span class="hs-comment">-- characters; but we don't know how long we've waited</span><span>
</span><span id="line-117"></span><span>                </span><span class="hs-comment">-- so far.</span><span>
</span><span id="line-118"></span><span>
</span><span id="line-119"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-120"></span><span class="hs-comment">-- hGetChar</span><span>
</span><span id="line-121"></span><span>
</span><span id="line-122"></span><span class="hs-comment">-- | Computation 'hGetChar' @hdl@ reads a character from the file or</span><span>
</span><span id="line-123"></span><span class="hs-comment">-- channel managed by @hdl@, blocking until a character is available.</span><span>
</span><span id="line-124"></span><span class="hs-comment">--</span><span>
</span><span id="line-125"></span><span class="hs-comment">-- This operation may fail with:</span><span>
</span><span id="line-126"></span><span class="hs-comment">--</span><span>
</span><span id="line-127"></span><span class="hs-comment">--  * 'isEOFError' if the end of file has been reached.</span><span>
</span><span id="line-128"></span><span>
</span><span id="line-129"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetChar"><span class="hs-identifier hs-type">hGetChar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span>
</span><span id="line-130"></span><span id="hGetChar"><span class="annot"><span class="annottext">hGetChar :: Handle -&gt; IO Char
</span><a href="GHC.IO.Handle.Text.html#hGetChar"><span class="hs-identifier hs-var hs-var">hGetChar</span></a></span></span><span> </span><span id="local-6989586621679557762"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557762"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-131"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; Handle -&gt; (Handle__ -&gt; IO Char) -&gt; IO Char
forall a. String -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle_"><span class="hs-identifier hs-var">wantReadableHandle_</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetChar&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557762"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO Char) -&gt; IO Char)
-&gt; (Handle__ -&gt; IO Char) -&gt; IO Char
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679557761"><span class="annot"><span class="annottext">handle_ :: Handle__
</span><a href="#local-6989586621679557761"><span class="hs-identifier hs-var">handle_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557726"><span id="local-6989586621679557727"><span id="local-6989586621679557728"><span id="local-6989586621679557729"><span id="local-6989586621679557730"><span id="local-6989586621679557731"><span id="local-6989586621679557732"><span id="local-6989586621679557733"><span id="local-6989586621679557734"><span id="local-6989586621679557735"><span id="local-6989586621679557736"><span id="local-6989586621679557737"><span id="local-6989586621679557738"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679557726"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-132"></span><span>
</span><span id="line-133"></span><span>  </span><span class="hs-comment">-- buffering mode makes no difference: we just read whatever is available</span><span>
</span><span id="line-134"></span><span>  </span><span class="hs-comment">-- from the device (blocking only if there is nothing available), and then</span><span>
</span><span id="line-135"></span><span>  </span><span class="hs-comment">-- return the first character.</span><span>
</span><span id="line-136"></span><span>  </span><span class="hs-comment">-- See [note Buffered Reading] in GHC.IO.Handle.Types</span><span>
</span><span id="line-137"></span><span>  </span><span id="local-6989586621679557725"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557725"><span class="hs-identifier hs-var">buf0</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557733"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-138"></span><span>
</span><span id="line-139"></span><span>  </span><span id="local-6989586621679557724"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557724"><span class="hs-identifier hs-var">buf1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557725"><span class="hs-identifier hs-var">buf0</span></a></span><span>
</span><span id="line-140"></span><span>             </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#readTextDevice"><span class="hs-identifier hs-var">readTextDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557761"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557725"><span class="hs-identifier hs-var">buf0</span></a></span><span>
</span><span id="line-141"></span><span>             </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; IO (Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557725"><span class="hs-identifier hs-var">buf0</span></a></span><span>
</span><span id="line-142"></span><span>
</span><span id="line-143"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679557723"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557723"><span class="hs-identifier hs-var">c1</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679557722"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557722"><span class="hs-identifier hs-var">i</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; IO (Char, Int)
</span><a href="GHC.IO.Buffer.html#readCharBuf"><span class="hs-identifier hs-var">readCharBuf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; RawCharBuffer
forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var hs-var">bufRaw</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557724"><span class="hs-identifier hs-var">buf1</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557724"><span class="hs-identifier hs-var">buf1</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-144"></span><span>  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679557718"><span class="annot"><span class="annottext">buf2 :: Buffer Char
</span><a href="#local-6989586621679557718"><span class="hs-identifier hs-var hs-var">buf2</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Char -&gt; Buffer Char
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAdjustL"><span class="hs-identifier hs-var">bufferAdjustL</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557722"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557724"><span class="hs-identifier hs-var">buf1</span></a></span><span>
</span><span id="line-145"></span><span>
</span><span id="line-146"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="#local-6989586621679557728"><span class="hs-identifier hs-var">haInputNL</span></a></span><span> </span><span class="annot"><span class="annottext">Newline -&gt; Newline -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="GHC.IO.Handle.Types.html#CRLF"><span class="hs-identifier hs-var">CRLF</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557723"><span class="hs-identifier hs-var">c1</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\r'</span></span><span>
</span><span id="line-147"></span><span>     </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-148"></span><span>            </span><span id="local-6989586621679557714"><span class="annot"><span class="annottext">Maybe (Buffer Char)
</span><a href="#local-6989586621679557714"><span class="hs-identifier hs-var">mbuf3</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557718"><span class="hs-identifier hs-var">buf2</span></a></span><span>
</span><span id="line-149"></span><span>                      </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Maybe (Buffer Char))
</span><a href="GHC.IO.Handle.Text.html#maybeFillReadBuffer"><span class="hs-identifier hs-var">maybeFillReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557761"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557718"><span class="hs-identifier hs-var">buf2</span></a></span><span>
</span><span id="line-150"></span><span>                      </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer Char) -&gt; IO (Maybe (Buffer Char))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Maybe (Buffer Char)
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557718"><span class="hs-identifier hs-var">buf2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-151"></span><span>
</span><span id="line-152"></span><span>            </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer Char)
</span><a href="#local-6989586621679557714"><span class="hs-identifier hs-var">mbuf3</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-153"></span><span>               </span><span class="hs-comment">-- EOF, so just return the '\r' we have</span><span>
</span><span id="line-154"></span><span>               </span><span class="annot"><span class="annottext">Maybe (Buffer Char)
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-155"></span><span>                  </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557733"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557718"><span class="hs-identifier hs-var">buf2</span></a></span><span>
</span><span id="line-156"></span><span>                  </span><span class="annot"><span class="annottext">Char -&gt; IO Char
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\r'</span></span><span>
</span><span id="line-157"></span><span>               </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679557712"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557712"><span class="hs-identifier hs-var">buf3</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-158"></span><span>                  </span><span class="hs-special">(</span><span id="local-6989586621679557711"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557711"><span class="hs-identifier hs-var">c2</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679557710"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557710"><span class="hs-identifier hs-var">i2</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; IO (Char, Int)
</span><a href="GHC.IO.Buffer.html#readCharBuf"><span class="hs-identifier hs-var">readCharBuf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; RawCharBuffer
forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var hs-var">bufRaw</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557718"><span class="hs-identifier hs-var">buf2</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557718"><span class="hs-identifier hs-var">buf2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-159"></span><span>                  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557711"><span class="hs-identifier hs-var">c2</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span>
</span><span id="line-160"></span><span>                     </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-161"></span><span>                       </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557733"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Buffer Char -&gt; Buffer Char
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAdjustL"><span class="hs-identifier hs-var">bufferAdjustL</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557710"><span class="hs-identifier hs-var">i2</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557712"><span class="hs-identifier hs-var">buf3</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-162"></span><span>                       </span><span class="annot"><span class="annottext">Char -&gt; IO Char
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span>
</span><span id="line-163"></span><span>                     </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-164"></span><span>                       </span><span class="hs-comment">-- not a \r\n sequence, so just return the \r</span><span>
</span><span id="line-165"></span><span>                       </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557733"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557712"><span class="hs-identifier hs-var">buf3</span></a></span><span>
</span><span id="line-166"></span><span>                       </span><span class="annot"><span class="annottext">Char -&gt; IO Char
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\r'</span></span><span>
</span><span id="line-167"></span><span>     </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-168"></span><span>            </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557733"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557718"><span class="hs-identifier hs-var">buf2</span></a></span><span>
</span><span id="line-169"></span><span>            </span><span class="annot"><span class="annottext">Char -&gt; IO Char
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557723"><span class="hs-identifier hs-var">c1</span></a></span><span>
</span><span id="line-170"></span><span>
</span><span id="line-171"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-172"></span><span class="hs-comment">-- hGetLine</span><span>
</span><span id="line-173"></span><span>
</span><span id="line-174"></span><span class="hs-comment">-- | Computation 'hGetLine' @hdl@ reads a line from the file or</span><span>
</span><span id="line-175"></span><span class="hs-comment">-- channel managed by @hdl@.</span><span>
</span><span id="line-176"></span><span class="hs-comment">--</span><span>
</span><span id="line-177"></span><span class="hs-comment">-- This operation may fail with:</span><span>
</span><span id="line-178"></span><span class="hs-comment">--</span><span>
</span><span id="line-179"></span><span class="hs-comment">--  * 'isEOFError' if the end of file is encountered when reading</span><span>
</span><span id="line-180"></span><span class="hs-comment">--    the /first/ character of the line.</span><span>
</span><span id="line-181"></span><span class="hs-comment">--</span><span>
</span><span id="line-182"></span><span class="hs-comment">-- If 'hGetLine' encounters end-of-file at any other point while reading</span><span>
</span><span id="line-183"></span><span class="hs-comment">-- in a line, it is treated as a line terminator and the (partial)</span><span>
</span><span id="line-184"></span><span class="hs-comment">-- line is returned.</span><span>
</span><span id="line-185"></span><span>
</span><span id="line-186"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetLine"><span class="hs-identifier hs-type">hGetLine</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-187"></span><span id="hGetLine"><span class="annot"><span class="annottext">hGetLine :: Handle -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetLine"><span class="hs-identifier hs-var hs-var">hGetLine</span></a></span></span><span> </span><span id="local-6989586621679557709"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557709"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-188"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; Handle -&gt; (Handle__ -&gt; IO String) -&gt; IO String
forall a. String -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle_"><span class="hs-identifier hs-var">wantReadableHandle_</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetLine&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557709"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO String) -&gt; IO String)
-&gt; (Handle__ -&gt; IO String) -&gt; IO String
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679557708"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557708"><span class="hs-identifier hs-var">handle_</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-189"></span><span>     </span><span class="annot"><span class="annottext">Handle__ -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetLineBuffered"><span class="hs-identifier hs-var">hGetLineBuffered</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557708"><span class="hs-identifier hs-var">handle_</span></a></span><span>
</span><span id="line-190"></span><span>
</span><span id="line-191"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetLineBuffered"><span class="hs-identifier hs-type">hGetLineBuffered</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-192"></span><span id="hGetLineBuffered"><span class="annot"><span class="annottext">hGetLineBuffered :: Handle__ -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetLineBuffered"><span class="hs-identifier hs-var hs-var">hGetLineBuffered</span></a></span></span><span> </span><span id="local-6989586621679557706"><span class="annot"><span class="annottext">handle_ :: Handle__
</span><a href="#local-6989586621679557706"><span class="hs-identifier hs-var">handle_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557688"><span id="local-6989586621679557689"><span id="local-6989586621679557690"><span id="local-6989586621679557691"><span id="local-6989586621679557692"><span id="local-6989586621679557693"><span id="local-6989586621679557694"><span id="local-6989586621679557695"><span id="local-6989586621679557696"><span id="local-6989586621679557697"><span id="local-6989586621679557698"><span id="local-6989586621679557699"><span id="local-6989586621679557700"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679557688"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-193"></span><span>  </span><span id="local-6989586621679557687"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557687"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557695"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-194"></span><span>  </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; [String] -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetLineBufferedLoop"><span class="hs-identifier hs-var">hGetLineBufferedLoop</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557706"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557687"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-195"></span><span>
</span><span id="line-196"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetLineBufferedLoop"><span class="hs-identifier hs-type">hGetLineBufferedLoop</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span>
</span><span id="line-197"></span><span>                     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-198"></span><span>                     </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-199"></span><span id="hGetLineBufferedLoop"><span class="annot"><span class="annottext">hGetLineBufferedLoop :: Handle__ -&gt; Buffer Char -&gt; [String] -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetLineBufferedLoop"><span class="hs-identifier hs-var hs-var">hGetLineBufferedLoop</span></a></span></span><span> </span><span id="local-6989586621679557684"><span class="annot"><span class="annottext">handle_ :: Handle__
</span><a href="#local-6989586621679557684"><span class="hs-identifier hs-var">handle_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557650"><span id="local-6989586621679557651"><span id="local-6989586621679557652"><span id="local-6989586621679557653"><span id="local-6989586621679557654"><span id="local-6989586621679557655"><span id="local-6989586621679557656"><span id="local-6989586621679557657"><span id="local-6989586621679557658"><span id="local-6989586621679557659"><span id="local-6989586621679557660"><span id="local-6989586621679557661"><span id="local-6989586621679557662"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679557650"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span>
</span><span id="line-200"></span><span>        </span><span id="local-6989586621679557649"><span class="annot"><span class="annottext">buf :: Buffer Char
</span><a href="#local-6989586621679557649"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557647"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557647"><span class="hs-identifier hs-var">r0</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557645"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557645"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557644"><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557644"><span class="hs-identifier hs-var">raw0</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span id="local-6989586621679557643"><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679557643"><span class="hs-identifier hs-var">xss</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-201"></span><span>  </span><span class="hs-keyword">let</span><span>
</span><span id="line-202"></span><span>        </span><span class="hs-comment">-- find the end-of-line character, if there is one</span><span>
</span><span id="line-203"></span><span>        </span><span id="local-6989586621679557637"><span class="annot"><span class="annottext">loop :: RawCharBuffer -&gt; Int -&gt; IO (Bool, Int)
</span><a href="#local-6989586621679557637"><span class="hs-identifier hs-var hs-var">loop</span></a></span></span><span> </span><span id="local-6989586621679557636"><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557636"><span class="hs-identifier hs-var">raw</span></a></span></span><span> </span><span id="local-6989586621679557635"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557635"><span class="hs-identifier hs-var">r</span></a></span></span><span>
</span><span id="line-204"></span><span>           </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557635"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557645"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Bool, Int) -&gt; IO (Bool, Int)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557645"><span class="hs-identifier hs-var">w</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-205"></span><span>           </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span>  </span><span class="hs-keyword">do</span><span>
</span><span id="line-206"></span><span>                </span><span class="hs-special">(</span><span id="local-6989586621679557634"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557634"><span class="hs-identifier hs-var">c</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679557633"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557633"><span class="hs-identifier hs-var">r'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; IO (Char, Int)
</span><a href="GHC.IO.Buffer.html#readCharBuf"><span class="hs-identifier hs-var">readCharBuf</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557636"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557635"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-207"></span><span>                </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557634"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span>
</span><span id="line-208"></span><span>                   </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">(Bool, Int) -&gt; IO (Bool, Int)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557635"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-comment">-- NB. not r': don't include the '\n'</span><span>
</span><span id="line-209"></span><span>                   </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; IO (Bool, Int)
</span><a href="#local-6989586621679557637"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557636"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557633"><span class="hs-identifier hs-var">r'</span></a></span><span>
</span><span id="line-210"></span><span>  </span><span class="hs-keyword">in</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-211"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679557632"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557632"><span class="hs-identifier hs-var">eol</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679557631"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557631"><span class="hs-identifier hs-var">off</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; IO (Bool, Int)
</span><a href="#local-6989586621679557637"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557644"><span class="hs-identifier hs-var">raw0</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557647"><span class="hs-identifier hs-var">r0</span></a></span><span>
</span><span id="line-212"></span><span>
</span><span id="line-213"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetLineBufferedLoop: r=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557647"><span class="hs-identifier hs-var">r0</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;, w=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557645"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;, off=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557631"><span class="hs-identifier hs-var">off</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-214"></span><span>
</span><span id="line-215"></span><span>  </span><span class="hs-special">(</span><span id="local-6989586621679557628"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557628"><span class="hs-identifier hs-var">xs</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679557627"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557627"><span class="hs-identifier hs-var">r'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="#local-6989586621679557652"><span class="hs-identifier hs-var">haInputNL</span></a></span><span> </span><span class="annot"><span class="annottext">Newline -&gt; Newline -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="GHC.IO.Handle.Types.html#CRLF"><span class="hs-identifier hs-var">CRLF</span></a></span><span>
</span><span id="line-216"></span><span>                </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; Int -&gt; String -&gt; IO (String, Int)
</span><a href="GHC.IO.Handle.Text.html#unpack_nl"><span class="hs-identifier hs-var">unpack_nl</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557644"><span class="hs-identifier hs-var">raw0</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557647"><span class="hs-identifier hs-var">r0</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557631"><span class="hs-identifier hs-var">off</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-217"></span><span>                </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679557625"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557625"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; Int -&gt; String -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#unpack"><span class="hs-identifier hs-var">unpack</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557644"><span class="hs-identifier hs-var">raw0</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557647"><span class="hs-identifier hs-var">r0</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557631"><span class="hs-identifier hs-var">off</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-218"></span><span>                        </span><span class="annot"><span class="annottext">(String, Int) -&gt; IO (String, Int)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557625"><span class="hs-identifier hs-var">xs</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557631"><span class="hs-identifier hs-var">off</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-219"></span><span>
</span><span id="line-220"></span><span>  </span><span class="hs-comment">-- if eol == True, then off is the offset of the '\n'</span><span>
</span><span id="line-221"></span><span>  </span><span class="hs-comment">-- otherwise off == w and the buffer is now empty.</span><span>
</span><span id="line-222"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557632"><span class="hs-identifier hs-var">eol</span></a></span><span> </span><span class="hs-comment">-- r' == off</span><span>
</span><span id="line-223"></span><span>        </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557657"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Buffer Char -&gt; Buffer Char
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAdjustL"><span class="hs-identifier hs-var">bufferAdjustL</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557631"><span class="hs-identifier hs-var">off</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557649"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-224"></span><span>                </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[String] -&gt; String
forall a. [[a]] -&gt; [a]
</span><a href="GHC.List.html#concat"><span class="hs-identifier hs-var">concat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[String] -&gt; [String]
forall a. [a] -&gt; [a]
</span><a href="GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557628"><span class="hs-identifier hs-var">xs</span></a></span><span class="annot"><span class="annottext">String -&gt; [String] -&gt; [String]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679557643"><span class="hs-identifier hs-var">xss</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-225"></span><span>        </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-226"></span><span>             </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679557621"><span class="annot"><span class="annottext">buf1 :: Buffer Char
</span><a href="#local-6989586621679557621"><span class="hs-identifier hs-var hs-var">buf1</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Char -&gt; Buffer Char
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAdjustL"><span class="hs-identifier hs-var">bufferAdjustL</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557627"><span class="hs-identifier hs-var">r'</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557649"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-227"></span><span>             </span><span id="local-6989586621679557620"><span class="annot"><span class="annottext">Maybe (Buffer Char)
</span><a href="#local-6989586621679557620"><span class="hs-identifier hs-var">maybe_buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Maybe (Buffer Char))
</span><a href="GHC.IO.Handle.Text.html#maybeFillReadBuffer"><span class="hs-identifier hs-var">maybeFillReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557684"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557621"><span class="hs-identifier hs-var">buf1</span></a></span><span>
</span><span id="line-228"></span><span>             </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer Char)
</span><a href="#local-6989586621679557620"><span class="hs-identifier hs-var">maybe_buf</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-229"></span><span>                </span><span class="hs-comment">-- Nothing indicates we caught an EOF, and we may have a</span><span>
</span><span id="line-230"></span><span>                </span><span class="hs-comment">-- partial line to return.</span><span>
</span><span id="line-231"></span><span>                </span><span class="annot"><span class="annottext">Maybe (Buffer Char)
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-232"></span><span>                     </span><span class="hs-comment">-- we reached EOF.  There might be a lone \r left</span><span>
</span><span id="line-233"></span><span>                     </span><span class="hs-comment">-- in the buffer, so check for that and</span><span>
</span><span id="line-234"></span><span>                     </span><span class="hs-comment">-- append it to the line if necessary.</span><span>
</span><span id="line-235"></span><span>                     </span><span class="hs-comment">--</span><span>
</span><span id="line-236"></span><span>                     </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679557619"><span class="annot"><span class="annottext">pre :: String
</span><a href="#local-6989586621679557619"><span class="hs-identifier hs-var hs-var">pre</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557621"><span class="hs-identifier hs-var">buf1</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;\r&quot;</span></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-237"></span><span>                     </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557657"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557621"><span class="hs-identifier hs-var">buf1</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-238"></span><span>                     </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679557618"><span class="annot"><span class="annottext">str :: String
</span><a href="#local-6989586621679557618"><span class="hs-identifier hs-var hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[String] -&gt; String
forall a. [[a]] -&gt; [a]
</span><a href="GHC.List.html#concat"><span class="hs-identifier hs-var">concat</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[String] -&gt; [String]
forall a. [a] -&gt; [a]
</span><a href="GHC.List.html#reverse"><span class="hs-identifier hs-var">reverse</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557619"><span class="hs-identifier hs-var">pre</span></a></span><span class="annot"><span class="annottext">String -&gt; [String] -&gt; [String]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557628"><span class="hs-identifier hs-var">xs</span></a></span><span class="annot"><span class="annottext">String -&gt; [String] -&gt; [String]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679557643"><span class="hs-identifier hs-var">xss</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-239"></span><span>                     </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String -&gt; Bool
forall a. [a] -&gt; Bool
</span><a href="GHC.List.html#null"><span class="hs-identifier hs-var">null</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557618"><span class="hs-identifier hs-var">str</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-240"></span><span>                        </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557618"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-241"></span><span>                        </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">IO String
forall a. IO a
</span><a href="GHC.IO.Handle.Internals.html#ioe_EOF"><span class="hs-identifier hs-var">ioe_EOF</span></a></span><span>
</span><span id="line-242"></span><span>                </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679557615"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557615"><span class="hs-identifier hs-var">new_buf</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-243"></span><span>                     </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; [String] -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetLineBufferedLoop"><span class="hs-identifier hs-var">hGetLineBufferedLoop</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557684"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557615"><span class="hs-identifier hs-var">new_buf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557628"><span class="hs-identifier hs-var">xs</span></a></span><span class="annot"><span class="annottext">String -&gt; [String] -&gt; [String]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">[String]
</span><a href="#local-6989586621679557643"><span class="hs-identifier hs-var">xss</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-244"></span><span>
</span><span id="line-245"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#maybeFillReadBuffer"><span class="hs-identifier hs-type">maybeFillReadBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-246"></span><span id="maybeFillReadBuffer"><span class="annot"><span class="annottext">maybeFillReadBuffer :: Handle__ -&gt; Buffer Char -&gt; IO (Maybe (Buffer Char))
</span><a href="GHC.IO.Handle.Text.html#maybeFillReadBuffer"><span class="hs-identifier hs-var hs-var">maybeFillReadBuffer</span></a></span></span><span> </span><span id="local-6989586621679557614"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557614"><span class="hs-identifier hs-var">handle_</span></a></span></span><span> </span><span id="local-6989586621679557613"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557613"><span class="hs-identifier hs-var">buf</span></a></span></span><span>
</span><span id="line-247"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">IO (Maybe (Buffer Char))
-&gt; (IOError -&gt; IO (Maybe (Buffer Char)))
-&gt; IO (Maybe (Buffer Char))
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catchException"><span class="hs-identifier hs-var">catchException</span></a></span><span>
</span><span id="line-248"></span><span>     </span><span class="hs-special">(</span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679557611"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557611"><span class="hs-identifier hs-var">buf'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Text.html#getSomeCharacters"><span class="hs-identifier hs-var">getSomeCharacters</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557614"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557613"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-249"></span><span>         </span><span class="annot"><span class="annottext">Maybe (Buffer Char) -&gt; IO (Maybe (Buffer Char))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Maybe (Buffer Char)
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557611"><span class="hs-identifier hs-var">buf'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-250"></span><span>     </span><span class="hs-special">)</span><span>
</span><span id="line-251"></span><span>     </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679557609"><span class="annot"><span class="annottext">IOError
</span><a href="#local-6989586621679557609"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; Bool
</span><a href="System.IO.Error.html#isEOFError"><span class="hs-identifier hs-var">isEOFError</span></a></span><span> </span><span class="annot"><span class="annottext">IOError
</span><a href="#local-6989586621679557609"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-252"></span><span>                  </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer Char) -&gt; IO (Maybe (Buffer Char))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer Char)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-253"></span><span>                  </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; IO (Maybe (Buffer Char))
forall a. IOError -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioError"><span class="hs-identifier hs-var">ioError</span></a></span><span> </span><span class="annot"><span class="annottext">IOError
</span><a href="#local-6989586621679557609"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-254"></span><span>
</span><span id="line-255"></span><span class="hs-comment">-- See GHC.IO.Buffer</span><span class="hs-cpp">
#define CHARBUF_UTF32
</span><span class="hs-comment">-- #define CHARBUF_UTF16</span><span>
</span><span id="line-258"></span><span>
</span><span id="line-259"></span><span class="hs-comment">-- NB. performance-critical code: eyeball the Core.</span><span>
</span><span id="line-260"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#unpack"><span class="hs-identifier hs-type">unpack</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawCharBuffer"><span class="hs-identifier hs-type">RawCharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-261"></span><span id="unpack"><span class="annot"><span class="annottext">unpack :: RawCharBuffer -&gt; Int -&gt; Int -&gt; String -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#unpack"><span class="hs-identifier hs-var hs-var">unpack</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557606"><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557606"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557605"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557605"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557604"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557604"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span id="local-6989586621679557603"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557603"><span class="hs-identifier hs-var">acc0</span></a></span></span><span>
</span><span id="line-262"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557605"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557604"><span class="hs-identifier hs-var">w</span></a></span><span>    </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557603"><span class="hs-identifier hs-var">acc0</span></a></span><span>
</span><span id="line-263"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-264"></span><span>  </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; (Ptr Char -&gt; IO String) -&gt; IO String
forall e a. RawBuffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Buffer.html#withRawBuffer"><span class="hs-identifier hs-var">withRawBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557606"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Char -&gt; IO String) -&gt; IO String)
-&gt; (Ptr Char -&gt; IO String) -&gt; IO String
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679557601"><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679557601"><span class="hs-identifier hs-var">pbuf</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-265"></span><span>    </span><span class="hs-keyword">let</span><span>
</span><span id="line-266"></span><span>        </span><span id="local-6989586621679557594"><span class="annot"><span class="annottext">unpackRB :: String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679557594"><span class="hs-identifier hs-var hs-var">unpackRB</span></a></span></span><span> </span><span id="local-6989586621679557593"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557593"><span class="hs-identifier hs-var">acc</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557592"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557592"><span class="hs-identifier hs-var">i</span></a></span></span><span>
</span><span id="line-267"></span><span>         </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557592"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557605"><span class="hs-identifier hs-var">r</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557593"><span class="hs-identifier hs-var">acc</span></a></span><span>
</span><span id="line-268"></span><span>         </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-269"></span><span>              </span><span class="hs-comment">-- Here, we are rather careful to only put an *evaluated* character</span><span>
</span><span id="line-270"></span><span>              </span><span class="hs-comment">-- in the output string. Due to pointer tagging, this allows the consumer</span><span>
</span><span id="line-271"></span><span>              </span><span class="hs-comment">-- to avoid ping-ponging between the actual consumer code and the thunk code</span><span class="hs-cpp">
#if defined(CHARBUF_UTF16)
</span><span>              </span><span class="hs-comment">-- reverse-order decoding of UTF-16</span><span>
</span><span id="line-274"></span><span>              </span><span class="hs-identifier">c2</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">peekElemOff</span><span> </span><span class="hs-identifier">pbuf</span><span> </span><span class="hs-identifier">i</span><span>
</span><span id="line-275"></span><span>              </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">c2</span><span> </span><span class="hs-operator">&lt;</span><span> </span><span class="hs-number">0xdc00</span><span> </span><span class="hs-operator">||</span><span> </span><span class="hs-identifier">c2</span><span> </span><span class="hs-operator">&gt;</span><span> </span><span class="hs-number">0xdffff</span><span class="hs-special">)</span><span>
</span><span id="line-276"></span><span>                 </span><span class="hs-keyword">then</span><span> </span><span class="hs-identifier">unpackRB</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">unsafeChr</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">c2</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">:</span><span> </span><span class="hs-identifier">acc</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">i</span><span class="hs-glyph">-</span><span class="hs-number">1</span><span class="hs-special">)</span><span>
</span><span id="line-277"></span><span>                 </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-identifier">c1</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-identifier">peekElemOff</span><span> </span><span class="hs-identifier">pbuf</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">i</span><span class="hs-glyph">-</span><span class="hs-number">1</span><span class="hs-special">)</span><span>
</span><span id="line-278"></span><span>                         </span><span class="hs-keyword">let</span><span> </span><span class="hs-identifier">c</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">c1</span><span> </span><span class="hs-glyph">-</span><span> </span><span class="hs-number">0xd800</span><span class="hs-special">)</span><span> </span><span class="hs-operator">*</span><span> </span><span class="hs-number">0x400</span><span> </span><span class="hs-operator">+</span><span>
</span><span id="line-279"></span><span>                                 </span><span class="hs-special">(</span><span class="hs-identifier">fromIntegral</span><span> </span><span class="hs-identifier">c2</span><span> </span><span class="hs-glyph">-</span><span> </span><span class="hs-number">0xdc00</span><span class="hs-special">)</span><span> </span><span class="hs-operator">+</span><span> </span><span class="hs-number">0x10000</span><span>
</span><span id="line-280"></span><span>                         </span><span class="hs-keyword">case</span><span> </span><span class="hs-identifier">desurrogatifyRoundtripCharacter</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">unsafeChr</span><span> </span><span class="hs-identifier">c</span><span class="hs-special">)</span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-281"></span><span>                           </span><span class="hs-special">{</span><span> </span><span class="hs-identifier">C#</span><span> </span><span class="hs-identifier">c#</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-identifier">unpackRB</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">C#</span><span> </span><span class="hs-identifier">c#</span><span> </span><span class="hs-glyph">:</span><span> </span><span class="hs-identifier">acc</span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="hs-identifier">i</span><span class="hs-glyph">-</span><span class="hs-number">2</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span class="hs-cpp">
#else
</span><span>              </span><span id="local-6989586621679557591"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557591"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Char -&gt; Int -&gt; IO Char
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; IO a
</span><a href="Foreign.Storable.html#peekElemOff"><span class="hs-identifier hs-var">peekElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679557601"><span class="hs-identifier hs-var">pbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557592"><span class="hs-identifier hs-var">i</span></a></span><span>
</span><span id="line-284"></span><span>              </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679557594"><span class="hs-identifier hs-var">unpackRB</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557591"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557593"><span class="hs-identifier hs-var">acc</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557592"><span class="hs-identifier hs-var">i</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span class="hs-cpp">
#endif
</span><span>     </span><span class="hs-keyword">in</span><span>
</span><span id="line-287"></span><span>     </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679557594"><span class="hs-identifier hs-var">unpackRB</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557603"><span class="hs-identifier hs-var">acc0</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557604"><span class="hs-identifier hs-var">w</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-288"></span><span>
</span><span id="line-289"></span><span class="hs-comment">-- NB. performance-critical code: eyeball the Core.</span><span>
</span><span id="line-290"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#unpack_nl"><span class="hs-identifier hs-type">unpack_nl</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawCharBuffer"><span class="hs-identifier hs-type">RawCharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-291"></span><span id="unpack_nl"><span class="annot"><span class="annottext">unpack_nl :: RawCharBuffer -&gt; Int -&gt; Int -&gt; String -&gt; IO (String, Int)
</span><a href="GHC.IO.Handle.Text.html#unpack_nl"><span class="hs-identifier hs-var hs-var">unpack_nl</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557589"><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557589"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557588"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557588"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557587"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557587"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span id="local-6989586621679557586"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557586"><span class="hs-identifier hs-var">acc0</span></a></span></span><span>
</span><span id="line-292"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557588"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557587"><span class="hs-identifier hs-var">w</span></a></span><span>    </span><span class="hs-glyph">=</span><span>  </span><span class="annot"><span class="annottext">(String, Int) -&gt; IO (String, Int)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557586"><span class="hs-identifier hs-var">acc0</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">)</span><span>
</span><span id="line-293"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-294"></span><span>  </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; (Ptr Char -&gt; IO (String, Int)) -&gt; IO (String, Int)
forall e a. RawBuffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Buffer.html#withRawBuffer"><span class="hs-identifier hs-var">withRawBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557589"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr Char -&gt; IO (String, Int)) -&gt; IO (String, Int))
-&gt; (Ptr Char -&gt; IO (String, Int)) -&gt; IO (String, Int)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679557585"><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679557585"><span class="hs-identifier hs-var">pbuf</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-295"></span><span>    </span><span class="hs-keyword">let</span><span>
</span><span id="line-296"></span><span>        </span><span id="local-6989586621679557567"><span class="annot"><span class="annottext">unpackRB :: String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679557567"><span class="hs-identifier hs-var hs-var">unpackRB</span></a></span></span><span> </span><span id="local-6989586621679557566"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557566"><span class="hs-identifier hs-var">acc</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557565"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557565"><span class="hs-identifier hs-var">i</span></a></span></span><span>
</span><span id="line-297"></span><span>         </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557565"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557588"><span class="hs-identifier hs-var">r</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557566"><span class="hs-identifier hs-var">acc</span></a></span><span>
</span><span id="line-298"></span><span>         </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-299"></span><span>              </span><span id="local-6989586621679557564"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557564"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Char -&gt; Int -&gt; IO Char
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; IO a
</span><a href="Foreign.Storable.html#peekElemOff"><span class="hs-identifier hs-var">peekElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679557585"><span class="hs-identifier hs-var">pbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557565"><span class="hs-identifier hs-var">i</span></a></span><span>
</span><span id="line-300"></span><span>              </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557564"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557565"><span class="hs-identifier hs-var">i</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E"><span class="hs-operator hs-var">&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557588"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-301"></span><span>                 </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-302"></span><span>                         </span><span id="local-6989586621679557562"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557562"><span class="hs-identifier hs-var">c1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Char -&gt; Int -&gt; IO Char
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; IO a
</span><a href="Foreign.Storable.html#peekElemOff"><span class="hs-identifier hs-var">peekElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679557585"><span class="hs-identifier hs-var">pbuf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557565"><span class="hs-identifier hs-var">i</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-303"></span><span>                         </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557562"><span class="hs-identifier hs-var">c1</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\r'</span></span><span class="hs-special">)</span><span>
</span><span id="line-304"></span><span>                            </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679557567"><span class="hs-identifier hs-var">unpackRB</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557566"><span class="hs-identifier hs-var">acc</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557565"><span class="hs-identifier hs-var">i</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span class="hs-special">)</span><span>
</span><span id="line-305"></span><span>                            </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679557567"><span class="hs-identifier hs-var">unpackRB</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557566"><span class="hs-identifier hs-var">acc</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557565"><span class="hs-identifier hs-var">i</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-306"></span><span>                 </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-307"></span><span>                         </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679557567"><span class="hs-identifier hs-var">unpackRB</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557564"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557566"><span class="hs-identifier hs-var">acc</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557565"><span class="hs-identifier hs-var">i</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-308"></span><span>     </span><span class="hs-keyword">in</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-309"></span><span>     </span><span id="local-6989586621679557561"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557561"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr Char -&gt; Int -&gt; IO Char
forall a. Storable a =&gt; Ptr a -&gt; Int -&gt; IO a
</span><a href="Foreign.Storable.html#peekElemOff"><span class="hs-identifier hs-var">peekElemOff</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Char
</span><a href="#local-6989586621679557585"><span class="hs-identifier hs-var">pbuf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557587"><span class="hs-identifier hs-var">w</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-310"></span><span>     </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557561"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\r'</span></span><span class="hs-special">)</span><span>
</span><span id="line-311"></span><span>        </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-312"></span><span>                </span><span class="hs-comment">-- If the last char is a '\r', we need to know whether or</span><span>
</span><span id="line-313"></span><span>                </span><span class="hs-comment">-- not it is followed by a '\n', so leave it in the buffer</span><span>
</span><span id="line-314"></span><span>                </span><span class="hs-comment">-- for now and just unpack the rest.</span><span>
</span><span id="line-315"></span><span>                </span><span id="local-6989586621679557560"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557560"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679557567"><span class="hs-identifier hs-var">unpackRB</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557586"><span class="hs-identifier hs-var">acc0</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557587"><span class="hs-identifier hs-var">w</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">2</span></span><span class="hs-special">)</span><span>
</span><span id="line-316"></span><span>                </span><span class="annot"><span class="annottext">(String, Int) -&gt; IO (String, Int)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557560"><span class="hs-identifier hs-var">str</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557587"><span class="hs-identifier hs-var">w</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-317"></span><span>        </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-318"></span><span>                </span><span id="local-6989586621679557559"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557559"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String -&gt; Int -&gt; IO String
</span><a href="#local-6989586621679557567"><span class="hs-identifier hs-var">unpackRB</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557586"><span class="hs-identifier hs-var">acc0</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557587"><span class="hs-identifier hs-var">w</span></a></span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-319"></span><span>                </span><span class="annot"><span class="annottext">(String, Int) -&gt; IO (String, Int)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557559"><span class="hs-identifier hs-var">str</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557587"><span class="hs-identifier hs-var">w</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-320"></span><span>
</span><span id="line-321"></span><span class="hs-comment">-- Note [#5536]</span><span>
</span><span id="line-322"></span><span class="hs-comment">--</span><span>
</span><span id="line-323"></span><span class="hs-comment">-- We originally had</span><span>
</span><span id="line-324"></span><span class="hs-comment">--</span><span>
</span><span id="line-325"></span><span class="hs-comment">--    let c' = desurrogatifyRoundtripCharacter c in</span><span>
</span><span id="line-326"></span><span class="hs-comment">--    c' `seq` unpackRB (c':acc) (i-1)</span><span>
</span><span id="line-327"></span><span class="hs-comment">--</span><span>
</span><span id="line-328"></span><span class="hs-comment">-- but this resulted in Core like</span><span>
</span><span id="line-329"></span><span class="hs-comment">--</span><span>
</span><span id="line-330"></span><span class="hs-comment">--    case (case x &lt;# y of True -&gt; C# e1; False -&gt; C# e2) of c</span><span>
</span><span id="line-331"></span><span class="hs-comment">--      C# _ -&gt; unpackRB (c:acc) (i-1)</span><span>
</span><span id="line-332"></span><span class="hs-comment">--</span><span>
</span><span id="line-333"></span><span class="hs-comment">-- which compiles into a continuation for the outer case, with each</span><span>
</span><span id="line-334"></span><span class="hs-comment">-- branch of the inner case building a C# and then jumping to the</span><span>
</span><span id="line-335"></span><span class="hs-comment">-- continuation.  We'd rather not have this extra jump, which makes</span><span>
</span><span id="line-336"></span><span class="hs-comment">-- quite a difference to performance (see #5536) It turns out that</span><span>
</span><span id="line-337"></span><span class="hs-comment">-- matching on the C# directly causes GHC to do the case-of-case,</span><span>
</span><span id="line-338"></span><span class="hs-comment">-- giving much straighter code.</span><span>
</span><span id="line-339"></span><span>
</span><span id="line-340"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-341"></span><span class="hs-comment">-- hGetContents</span><span>
</span><span id="line-342"></span><span>
</span><span id="line-343"></span><span class="hs-comment">-- hGetContents on a DuplexHandle only affects the read side: you can</span><span>
</span><span id="line-344"></span><span class="hs-comment">-- carry on writing to it afterwards.</span><span>
</span><span id="line-345"></span><span>
</span><span id="line-346"></span><span class="hs-comment">-- | Computation 'hGetContents' @hdl@ returns the list of characters</span><span>
</span><span id="line-347"></span><span class="hs-comment">-- corresponding to the unread portion of the channel or file managed</span><span>
</span><span id="line-348"></span><span class="hs-comment">-- by @hdl@, which is put into an intermediate state, /semi-closed/.</span><span>
</span><span id="line-349"></span><span class="hs-comment">-- In this state, @hdl@ is effectively closed,</span><span>
</span><span id="line-350"></span><span class="hs-comment">-- but items are read from @hdl@ on demand and accumulated in a special</span><span>
</span><span id="line-351"></span><span class="hs-comment">-- list returned by 'hGetContents' @hdl@.</span><span>
</span><span id="line-352"></span><span class="hs-comment">--</span><span>
</span><span id="line-353"></span><span class="hs-comment">-- Any operation that fails because a handle is closed,</span><span>
</span><span id="line-354"></span><span class="hs-comment">-- also fails if a handle is semi-closed.  The only exception is</span><span>
</span><span id="line-355"></span><span class="hs-comment">-- 'System.IO.hClose'.  A semi-closed handle becomes closed:</span><span>
</span><span id="line-356"></span><span class="hs-comment">--</span><span>
</span><span id="line-357"></span><span class="hs-comment">--  * if 'System.IO.hClose' is applied to it;</span><span>
</span><span id="line-358"></span><span class="hs-comment">--</span><span>
</span><span id="line-359"></span><span class="hs-comment">--  * if an I\/O error occurs when reading an item from the handle;</span><span>
</span><span id="line-360"></span><span class="hs-comment">--</span><span>
</span><span id="line-361"></span><span class="hs-comment">--  * or once the entire contents of the handle has been read.</span><span>
</span><span id="line-362"></span><span class="hs-comment">--</span><span>
</span><span id="line-363"></span><span class="hs-comment">-- Once a semi-closed handle becomes closed, the contents of the</span><span>
</span><span id="line-364"></span><span class="hs-comment">-- associated list becomes fixed.  The contents of this final list is</span><span>
</span><span id="line-365"></span><span class="hs-comment">-- only partially specified: it will contain at least all the items of</span><span>
</span><span id="line-366"></span><span class="hs-comment">-- the stream that were evaluated prior to the handle becoming closed.</span><span>
</span><span id="line-367"></span><span class="hs-comment">--</span><span>
</span><span id="line-368"></span><span class="hs-comment">-- Any I\/O errors encountered while a handle is semi-closed are simply</span><span>
</span><span id="line-369"></span><span class="hs-comment">-- discarded.</span><span>
</span><span id="line-370"></span><span class="hs-comment">--</span><span>
</span><span id="line-371"></span><span class="hs-comment">-- This operation may fail with:</span><span>
</span><span id="line-372"></span><span class="hs-comment">--</span><span>
</span><span id="line-373"></span><span class="hs-comment">--  * 'isEOFError' if the end of file has been reached.</span><span>
</span><span id="line-374"></span><span>
</span><span id="line-375"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetContents"><span class="hs-identifier hs-type">hGetContents</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-376"></span><span id="hGetContents"><span class="annot"><span class="annottext">hGetContents :: Handle -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetContents"><span class="hs-identifier hs-var hs-var">hGetContents</span></a></span></span><span> </span><span id="local-6989586621679557558"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557558"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-377"></span><span>   </span><span class="annot"><span class="annottext">String
-&gt; Handle -&gt; (Handle__ -&gt; IO (Handle__, String)) -&gt; IO String
forall a.
String -&gt; Handle -&gt; (Handle__ -&gt; IO (Handle__, a)) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle"><span class="hs-identifier hs-var">wantReadableHandle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetContents&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557558"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO (Handle__, String)) -&gt; IO String)
-&gt; (Handle__ -&gt; IO (Handle__, String)) -&gt; IO String
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679557556"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557556"><span class="hs-identifier hs-var">handle_</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-378"></span><span>      </span><span id="local-6989586621679557555"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557555"><span class="hs-identifier hs-var">xs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#lazyRead"><span class="hs-identifier hs-var">lazyRead</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557558"><span class="hs-identifier hs-var">handle</span></a></span><span>
</span><span id="line-379"></span><span>      </span><span class="annot"><span class="annottext">(Handle__, String) -&gt; IO (Handle__, String)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557556"><span class="hs-identifier hs-var">handle_</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">haType :: HandleType
</span><a href="GHC.IO.Handle.Types.html#haType"><span class="hs-identifier hs-var">haType</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#SemiClosedHandle"><span class="hs-identifier hs-var">SemiClosedHandle</span></a></span><span class="hs-special">}</span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557555"><span class="hs-identifier hs-var">xs</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-380"></span><span>
</span><span id="line-381"></span><span class="hs-comment">-- Note that someone may close the semi-closed handle (or change its</span><span>
</span><span id="line-382"></span><span class="hs-comment">-- buffering), so each time these lazy read functions are pulled on,</span><span>
</span><span id="line-383"></span><span class="hs-comment">-- they have to check whether the handle has indeed been closed.</span><span>
</span><span id="line-384"></span><span>
</span><span id="line-385"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#lazyRead"><span class="hs-identifier hs-type">lazyRead</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-386"></span><span id="lazyRead"><span class="annot"><span class="annottext">lazyRead :: Handle -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#lazyRead"><span class="hs-identifier hs-var hs-var">lazyRead</span></a></span></span><span> </span><span id="local-6989586621679557552"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557552"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-387"></span><span>   </span><span class="annot"><span class="annottext">IO String -&gt; IO String
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.Unsafe.html#unsafeInterleaveIO"><span class="hs-identifier hs-var">unsafeInterleaveIO</span></a></span><span> </span><span class="annot"><span class="annottext">(IO String -&gt; IO String) -&gt; IO String -&gt; IO String
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-388"></span><span>        </span><span class="annot"><span class="annottext">String
-&gt; Handle -&gt; (Handle__ -&gt; IO (Handle__, String)) -&gt; IO String
forall a.
String -&gt; Handle -&gt; (Handle__ -&gt; IO (Handle__, a)) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#withHandle"><span class="hs-identifier hs-var">withHandle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetContents&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557552"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO (Handle__, String)) -&gt; IO String)
-&gt; (Handle__ -&gt; IO (Handle__, String)) -&gt; IO String
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679557549"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557549"><span class="hs-identifier hs-var">handle_</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-389"></span><span>        </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; HandleType
</span><a href="GHC.IO.Handle.Types.html#haType"><span class="hs-identifier hs-var hs-var">haType</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557549"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-390"></span><span>          </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#SemiClosedHandle"><span class="hs-identifier hs-var">SemiClosedHandle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; Handle__ -&gt; IO (Handle__, String)
</span><a href="GHC.IO.Handle.Text.html#lazyReadBuffered"><span class="hs-identifier hs-var">lazyReadBuffered</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557552"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557549"><span class="hs-identifier hs-var">handle_</span></a></span><span>
</span><span id="line-391"></span><span>          </span><span class="annot"><span class="annottext">HandleType
</span><a href="GHC.IO.Handle.Types.html#ClosedHandle"><span class="hs-identifier hs-var">ClosedHandle</span></a></span><span>
</span><span id="line-392"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; IO (Handle__, String)
forall a. IOError -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span>
</span><span id="line-393"></span><span>                  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; String
-&gt; String
-&gt; Maybe CInt
-&gt; Maybe String
-&gt; IOError
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle -&gt; Maybe Handle
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557552"><span class="hs-identifier hs-var">handle</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#IllegalOperation"><span class="hs-identifier hs-var">IllegalOperation</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetContents&quot;</span></span><span>
</span><span id="line-394"></span><span>                        </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;delayed read on closed handle&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe String
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-395"></span><span>          </span><span class="annot"><span class="annottext">HandleType
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; IO (Handle__, String)
forall a. IOError -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span>
</span><span id="line-396"></span><span>                  </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; String
-&gt; String
-&gt; Maybe CInt
-&gt; Maybe String
-&gt; IOError
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle -&gt; Maybe Handle
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557552"><span class="hs-identifier hs-var">handle</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#IllegalOperation"><span class="hs-identifier hs-var">IllegalOperation</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetContents&quot;</span></span><span>
</span><span id="line-397"></span><span>                        </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;illegal handle type&quot;</span></span><span> </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe String
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-398"></span><span>
</span><span id="line-399"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#lazyReadBuffered"><span class="hs-identifier hs-type">lazyReadBuffered</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-400"></span><span id="lazyReadBuffered"><span class="annot"><span class="annottext">lazyReadBuffered :: Handle -&gt; Handle__ -&gt; IO (Handle__, String)
</span><a href="GHC.IO.Handle.Text.html#lazyReadBuffered"><span class="hs-identifier hs-var hs-var">lazyReadBuffered</span></a></span></span><span> </span><span id="local-6989586621679557543"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557543"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679557542"><span class="annot"><span class="annottext">handle_ :: Handle__
</span><a href="#local-6989586621679557542"><span class="hs-identifier hs-var">handle_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557510"><span id="local-6989586621679557511"><span id="local-6989586621679557512"><span id="local-6989586621679557513"><span id="local-6989586621679557514"><span id="local-6989586621679557515"><span id="local-6989586621679557516"><span id="local-6989586621679557517"><span id="local-6989586621679557518"><span id="local-6989586621679557519"><span id="local-6989586621679557520"><span id="local-6989586621679557521"><span id="local-6989586621679557522"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679557510"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-401"></span><span>   </span><span id="local-6989586621679557509"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557509"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557517"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-402"></span><span>   </span><span class="annot"><span class="annottext">IO (Handle__, String)
-&gt; (IOError -&gt; IO (Handle__, String)) -&gt; IO (Handle__, String)
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catch"><span class="hs-identifier hs-var">Exception.catch</span></a></span><span>
</span><span id="line-403"></span><span>        </span><span class="hs-special">(</span><span class="hs-keyword">do</span><span>
</span><span id="line-404"></span><span>            </span><span id="local-6989586621679557507"><span class="annot"><span class="annottext">buf' :: Buffer Char
</span><a href="#local-6989586621679557507"><span class="hs-identifier hs-var">buf'</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557501"><span id="local-6989586621679557502"><span id="local-6989586621679557503"><span id="local-6989586621679557504"><span id="local-6989586621679557505"><span id="local-6989586621679557506"><span class="annot"><span class="annottext">Int
Word64
RawCharBuffer
BufferState
bufState :: forall e. Buffer e -&gt; BufferState
bufSize :: forall e. Buffer e -&gt; Int
bufOffset :: forall e. Buffer e -&gt; Word64
bufR :: Int
bufL :: Int
bufOffset :: Word64
bufSize :: Int
bufState :: BufferState
bufRaw :: RawCharBuffer
bufR :: forall e. Buffer e -&gt; Int
bufL :: forall e. Buffer e -&gt; Int
bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Text.html#getSomeCharacters"><span class="hs-identifier hs-var">getSomeCharacters</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557542"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557509"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-405"></span><span>            </span><span id="local-6989586621679557497"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557497"><span class="hs-identifier hs-var">lazy_rest</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#lazyRead"><span class="hs-identifier hs-var">lazyRead</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557543"><span class="hs-identifier hs-var">h</span></a></span><span>
</span><span id="line-406"></span><span>            </span><span class="hs-special">(</span><span id="local-6989586621679557496"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557496"><span class="hs-identifier hs-var">s</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679557495"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557495"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="#local-6989586621679557512"><span class="hs-identifier hs-var">haInputNL</span></a></span><span> </span><span class="annot"><span class="annottext">Newline -&gt; Newline -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="GHC.IO.Handle.Types.html#CRLF"><span class="hs-identifier hs-var">CRLF</span></a></span><span>
</span><span id="line-407"></span><span>                         </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; Int -&gt; String -&gt; IO (String, Int)
</span><a href="GHC.IO.Handle.Text.html#unpack_nl"><span class="hs-identifier hs-var">unpack_nl</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557506"><span class="hs-identifier hs-var">bufRaw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557502"><span class="hs-identifier hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557501"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557497"><span class="hs-identifier hs-var">lazy_rest</span></a></span><span>
</span><span id="line-408"></span><span>                         </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679557494"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557494"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; Int -&gt; String -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#unpack"><span class="hs-identifier hs-var">unpack</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557506"><span class="hs-identifier hs-var">bufRaw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557502"><span class="hs-identifier hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557501"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557497"><span class="hs-identifier hs-var">lazy_rest</span></a></span><span>
</span><span id="line-409"></span><span>                                 </span><span class="annot"><span class="annottext">(String, Int) -&gt; IO (String, Int)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557494"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557501"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-410"></span><span>            </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; Buffer Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557517"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Buffer Char -&gt; Buffer Char
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAdjustL"><span class="hs-identifier hs-var">bufferAdjustL</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557495"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557507"><span class="hs-identifier hs-var">buf'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-411"></span><span>            </span><span class="annot"><span class="annottext">(Handle__, String) -&gt; IO (Handle__, String)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557542"><span class="hs-identifier hs-var">handle_</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557496"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-412"></span><span>        </span><span class="hs-special">)</span><span>
</span><span id="line-413"></span><span>        </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679557493"><span class="annot"><span class="annottext">IOError
</span><a href="#local-6989586621679557493"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679557492"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557492"><span class="hs-identifier hs-var">handle_'</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Maybe SomeException
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO (Handle__, Maybe SomeException)
</span><a href="GHC.IO.Handle.Internals.html#hClose_help"><span class="hs-identifier hs-var">hClose_help</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557542"><span class="hs-identifier hs-var">handle_</span></a></span><span>
</span><span id="line-414"></span><span>                  </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetContents caught: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">IOError -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">IOError
</span><a href="#local-6989586621679557493"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-415"></span><span>                  </span><span class="hs-comment">-- We might have a \r cached in CRLF mode.  So we</span><span>
</span><span id="line-416"></span><span>                  </span><span class="hs-comment">-- need to check for that and return it:</span><span>
</span><span id="line-417"></span><span>                  </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679557489"><span class="annot"><span class="annottext">r :: String
</span><a href="#local-6989586621679557489"><span class="hs-identifier hs-var hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; Bool
</span><a href="System.IO.Error.html#isEOFError"><span class="hs-identifier hs-var">isEOFError</span></a></span><span> </span><span class="annot"><span class="annottext">IOError
</span><a href="#local-6989586621679557493"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-418"></span><span>                             </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557509"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-419"></span><span>                                     </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;\r&quot;</span></span><span>
</span><span id="line-420"></span><span>                                     </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-421"></span><span>                             </span><span class="hs-keyword">else</span><span>
</span><span id="line-422"></span><span>                                  </span><span class="annot"><span class="annottext">IOError -&gt; String
forall a e. Exception e =&gt; e -&gt; a
</span><a href="GHC.Exception.html#throw"><span class="hs-identifier hs-var">throw</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IOError -&gt; String -&gt; Handle -&gt; IOError
</span><a href="GHC.IO.Handle.Internals.html#augmentIOError"><span class="hs-identifier hs-var">augmentIOError</span></a></span><span> </span><span class="annot"><span class="annottext">IOError
</span><a href="#local-6989586621679557493"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetContents&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557543"><span class="hs-identifier hs-var">h</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-423"></span><span>
</span><span id="line-424"></span><span>                  </span><span class="annot"><span class="annottext">(Handle__, String) -&gt; IO (Handle__, String)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557492"><span class="hs-identifier hs-var">handle_'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557489"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-425"></span><span>        </span><span class="hs-special">)</span><span>
</span><span id="line-426"></span><span>
</span><span id="line-427"></span><span class="hs-comment">-- ensure we have some characters in the buffer</span><span>
</span><span id="line-428"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#getSomeCharacters"><span class="hs-identifier hs-type">getSomeCharacters</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span>
</span><span id="line-429"></span><span id="getSomeCharacters"><span class="annot"><span class="annottext">getSomeCharacters :: Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Text.html#getSomeCharacters"><span class="hs-identifier hs-var hs-var">getSomeCharacters</span></a></span></span><span> </span><span id="local-6989586621679557486"><span class="annot"><span class="annottext">handle_ :: Handle__
</span><a href="#local-6989586621679557486"><span class="hs-identifier hs-var">handle_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557459"><span id="local-6989586621679557460"><span id="local-6989586621679557461"><span id="local-6989586621679557462"><span id="local-6989586621679557463"><span id="local-6989586621679557464"><span id="local-6989586621679557465"><span id="local-6989586621679557466"><span id="local-6989586621679557467"><span id="local-6989586621679557468"><span id="local-6989586621679557469"><span id="local-6989586621679557470"><span id="local-6989586621679557471"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679557459"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span id="local-6989586621679557458"><span class="annot"><span class="annottext">buf :: Buffer Char
</span><a href="#local-6989586621679557458"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557452"><span id="local-6989586621679557453"><span id="local-6989586621679557454"><span id="local-6989586621679557455"><span id="local-6989586621679557456"><span id="local-6989586621679557457"><span class="annot"><span class="annottext">Int
Word64
RawCharBuffer
BufferState
bufR :: Int
bufL :: Int
bufOffset :: Word64
bufSize :: Int
bufState :: BufferState
bufRaw :: RawCharBuffer
bufState :: forall e. Buffer e -&gt; BufferState
bufSize :: forall e. Buffer e -&gt; Int
bufOffset :: forall e. Buffer e -&gt; Word64
bufR :: forall e. Buffer e -&gt; Int
bufL :: forall e. Buffer e -&gt; Int
bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="#local-6989586621679557452"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-430"></span><span>  </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var">bufferElems</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557458"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-431"></span><span>
</span><span id="line-432"></span><span>    </span><span class="hs-comment">-- buffer empty: read some more</span><span>
</span><span id="line-433"></span><span>    </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#readTextDevice"><span class="hs-identifier hs-var">readTextDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557486"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557458"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-434"></span><span>
</span><span id="line-435"></span><span>    </span><span class="hs-comment">-- if the buffer has a single '\r' in it and we're doing newline</span><span>
</span><span id="line-436"></span><span>    </span><span class="hs-comment">-- translation: read some more</span><span>
</span><span id="line-437"></span><span>    </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="#local-6989586621679557461"><span class="hs-identifier hs-var">haInputNL</span></a></span><span> </span><span class="annot"><span class="annottext">Newline -&gt; Newline -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="GHC.IO.Handle.Types.html#CRLF"><span class="hs-identifier hs-var">CRLF</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-438"></span><span>      </span><span class="hs-special">(</span><span id="local-6989586621679557450"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557450"><span class="hs-identifier hs-var">c</span></a></span></span><span class="hs-special">,</span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; IO (Char, Int)
</span><a href="GHC.IO.Buffer.html#readCharBuf"><span class="hs-identifier hs-var">readCharBuf</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557457"><span class="hs-identifier hs-var">bufRaw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557453"><span class="hs-identifier hs-var">bufL</span></a></span><span>
</span><span id="line-439"></span><span>      </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557450"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\r'</span></span><span>
</span><span id="line-440"></span><span>         </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-comment">-- shuffle the '\r' to the beginning.  This is only safe</span><span>
</span><span id="line-441"></span><span>                 </span><span class="hs-comment">-- if we're about to call readTextDevice, otherwise it</span><span>
</span><span id="line-442"></span><span>                 </span><span class="hs-comment">-- would mess up flushCharBuffer.</span><span>
</span><span id="line-443"></span><span>                 </span><span class="hs-comment">-- See [note Buffer Flushing], GHC.IO.Handle.Types</span><span>
</span><span id="line-444"></span><span>                 </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; Char -&gt; IO Int
</span><a href="GHC.IO.Buffer.html#writeCharBuf"><span class="hs-identifier hs-var">writeCharBuf</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557457"><span class="hs-identifier hs-var">bufRaw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\r'</span></span><span>
</span><span id="line-445"></span><span>                 </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679557448"><span class="annot"><span class="annottext">buf' :: Buffer Char
</span><a href="#local-6989586621679557448"><span class="hs-identifier hs-var hs-var">buf'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557458"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-446"></span><span>                 </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#readTextDevice"><span class="hs-identifier hs-var">readTextDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557486"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557448"><span class="hs-identifier hs-var">buf'</span></a></span><span>
</span><span id="line-447"></span><span>         </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-448"></span><span>                 </span><span class="annot"><span class="annottext">Buffer Char -&gt; IO (Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557458"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-449"></span><span>
</span><span id="line-450"></span><span>    </span><span class="hs-comment">-- buffer has some chars in it already: just return it</span><span>
</span><span id="line-451"></span><span>    </span><span id="local-6989586621679557447"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557447"><span class="hs-identifier hs-var">_otherwise</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-452"></span><span>      </span><span class="annot"><span class="annottext">Buffer Char -&gt; IO (Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557458"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-453"></span><span>
</span><span id="line-454"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-455"></span><span class="hs-comment">-- hGetContents'</span><span>
</span><span id="line-456"></span><span>
</span><span id="line-457"></span><span class="hs-comment">-- We read everything into a list of CharBuffer chunks, and convert it lazily</span><span>
</span><span id="line-458"></span><span class="hs-comment">-- to a string, which minimizes memory usage.</span><span>
</span><span id="line-459"></span><span class="hs-comment">-- In the worst case, space usage is at most that of the complete String,</span><span>
</span><span id="line-460"></span><span class="hs-comment">-- as the chunks can be garbage collected progressively.</span><span>
</span><span id="line-461"></span><span class="hs-comment">-- For streaming consumers, space usage is at most that of the list of chunks.</span><span>
</span><span id="line-462"></span><span>
</span><span id="line-463"></span><span class="hs-comment">-- | The 'hGetContents'' operation reads all input on the given handle</span><span>
</span><span id="line-464"></span><span class="hs-comment">-- before returning it as a 'String' and closing the handle.</span><span>
</span><span id="line-465"></span><span class="hs-comment">--</span><span>
</span><span id="line-466"></span><span class="hs-comment">-- @since 4.15.0.0</span><span>
</span><span id="line-467"></span><span>
</span><span id="line-468"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetContents%27"><span class="hs-identifier hs-type">hGetContents'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-469"></span><span id="hGetContents%27"><span class="annot"><span class="annottext">hGetContents' :: Handle -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#hGetContents%27"><span class="hs-identifier hs-var hs-var">hGetContents'</span></a></span></span><span> </span><span id="local-6989586621679557446"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557446"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-470"></span><span>    </span><span id="local-6989586621679557445"><span class="annot"><span class="annottext">Either SomeException String
</span><a href="#local-6989586621679557445"><span class="hs-identifier hs-var">es</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">String
-&gt; Handle
-&gt; (Handle__ -&gt; IO (Handle__, Either SomeException String))
-&gt; IO (Either SomeException String)
forall a.
String -&gt; Handle -&gt; (Handle__ -&gt; IO (Handle__, a)) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle"><span class="hs-identifier hs-var">wantReadableHandle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetContents'&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557446"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle -&gt; Handle__ -&gt; IO (Handle__, Either SomeException String)
</span><a href="GHC.IO.Handle.Text.html#strictRead"><span class="hs-identifier hs-var">strictRead</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557446"><span class="hs-identifier hs-var">handle</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-471"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Either SomeException String
</span><a href="#local-6989586621679557445"><span class="hs-identifier hs-var">es</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-472"></span><span>      </span><span class="annot"><a href="Data.Either.html#Right"><span class="hs-identifier hs-type">Right</span></a></span><span> </span><span id="local-6989586621679557443"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557443"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557443"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-473"></span><span>      </span><span class="annot"><a href="Data.Either.html#Left"><span class="hs-identifier hs-type">Left</span></a></span><span> </span><span id="local-6989586621679557442"><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679557442"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-474"></span><span>          </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; Maybe IOError
forall e. Exception e =&gt; SomeException -&gt; Maybe e
</span><a href="GHC.Exception.Type.html#fromException"><span class="hs-identifier hs-var">fromException</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679557442"><span class="hs-identifier hs-var">e</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-475"></span><span>            </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679557440"><span class="annot"><span class="annottext">IOError
</span><a href="#local-6989586621679557440"><span class="hs-identifier hs-var">ioe</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; IO String
forall e a. Exception e =&gt; e -&gt; IO a
</span><a href="GHC.IO.html#throwIO"><span class="hs-identifier hs-var">throwIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">IOError -&gt; String -&gt; Handle -&gt; IOError
</span><a href="GHC.IO.Handle.Internals.html#augmentIOError"><span class="hs-identifier hs-var">augmentIOError</span></a></span><span> </span><span class="annot"><span class="annottext">IOError
</span><a href="#local-6989586621679557440"><span class="hs-identifier hs-var">ioe</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetContents'&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557446"><span class="hs-identifier hs-var">handle</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-476"></span><span>            </span><span class="annot"><span class="annottext">Maybe IOError
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; IO String
forall e a. Exception e =&gt; e -&gt; IO a
</span><a href="GHC.IO.html#throwIO"><span class="hs-identifier hs-var">throwIO</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679557442"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-477"></span><span>
</span><span id="line-478"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#strictRead"><span class="hs-identifier hs-type">strictRead</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="Data.Either.html#Either"><span class="hs-identifier hs-type">Either</span></a></span><span> </span><span class="annot"><a href="GHC.Exception.Type.html#SomeException"><span class="hs-identifier hs-type">SomeException</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-479"></span><span id="strictRead"><span class="annot"><span class="annottext">strictRead :: Handle -&gt; Handle__ -&gt; IO (Handle__, Either SomeException String)
</span><a href="GHC.IO.Handle.Text.html#strictRead"><span class="hs-identifier hs-var hs-var">strictRead</span></a></span></span><span> </span><span id="local-6989586621679557438"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557438"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679557437"><span class="annot"><span class="annottext">handle_ :: Handle__
</span><a href="#local-6989586621679557437"><span class="hs-identifier hs-var">handle_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557414"><span id="local-6989586621679557415"><span id="local-6989586621679557416"><span id="local-6989586621679557417"><span id="local-6989586621679557418"><span id="local-6989586621679557419"><span id="local-6989586621679557420"><span id="local-6989586621679557421"><span id="local-6989586621679557422"><span id="local-6989586621679557423"><span id="local-6989586621679557424"><span id="local-6989586621679557425"><span id="local-6989586621679557426"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679557414"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-480"></span><span>    </span><span id="local-6989586621679557413"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557413"><span class="hs-identifier hs-var">cbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557421"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-481"></span><span>    </span><span id="local-6989586621679557412"><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557412"><span class="hs-identifier hs-var">cbufs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; [Buffer Char] -&gt; Buffer Char -&gt; IO [Buffer Char]
</span><a href="GHC.IO.Handle.Text.html#strictReadLoop%27"><span class="hs-identifier hs-var">strictReadLoop'</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557437"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557413"><span class="hs-identifier hs-var">cbuf</span></a></span><span>
</span><span id="line-482"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679557410"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557410"><span class="hs-identifier hs-var">handle_'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679557409"><span class="annot"><span class="annottext">Maybe SomeException
</span><a href="#local-6989586621679557409"><span class="hs-identifier hs-var">me</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO (Handle__, Maybe SomeException)
</span><a href="GHC.IO.Handle.Internals.html#hClose_help"><span class="hs-identifier hs-var">hClose_help</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557437"><span class="hs-identifier hs-var">handle_</span></a></span><span>
</span><span id="line-483"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe SomeException
</span><a href="#local-6989586621679557409"><span class="hs-identifier hs-var">me</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-484"></span><span>      </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679557408"><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679557408"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(Handle__, Either SomeException String)
-&gt; IO (Handle__, Either SomeException String)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557410"><span class="hs-identifier hs-var">handle_'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">SomeException -&gt; Either SomeException String
forall a b. a -&gt; Either a b
</span><a href="Data.Either.html#Left"><span class="hs-identifier hs-var">Left</span></a></span><span> </span><span class="annot"><span class="annottext">SomeException
</span><a href="#local-6989586621679557408"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-485"></span><span>      </span><span class="annot"><span class="annottext">Maybe SomeException
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-486"></span><span>        </span><span id="local-6989586621679557407"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557407"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Newline -&gt; [Buffer Char] -&gt; String -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#lazyBuffersToString"><span class="hs-identifier hs-var">lazyBuffersToString</span></a></span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="#local-6989586621679557416"><span class="hs-identifier hs-var">haInputNL</span></a></span><span> </span><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557412"><span class="hs-identifier hs-var">cbufs</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span>
</span><span id="line-487"></span><span>        </span><span class="annot"><span class="annottext">(Handle__, Either SomeException String)
-&gt; IO (Handle__, Either SomeException String)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557410"><span class="hs-identifier hs-var">handle_'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; Either SomeException String
forall a b. b -&gt; Either a b
</span><a href="Data.Either.html#Right"><span class="hs-identifier hs-var">Right</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557407"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-488"></span><span>
</span><span id="line-489"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#strictReadLoop"><span class="hs-identifier hs-type">strictReadLoop</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-490"></span><span id="strictReadLoop"><span class="annot"><span class="annottext">strictReadLoop :: Handle__ -&gt; [Buffer Char] -&gt; Buffer Char -&gt; IO [Buffer Char]
</span><a href="GHC.IO.Handle.Text.html#strictReadLoop"><span class="hs-identifier hs-var hs-var">strictReadLoop</span></a></span></span><span> </span><span id="local-6989586621679557404"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557404"><span class="hs-identifier hs-var">handle_</span></a></span></span><span> </span><span id="local-6989586621679557403"><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557403"><span class="hs-identifier hs-var">cbufs</span></a></span></span><span> </span><span id="local-6989586621679557402"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557402"><span class="hs-identifier hs-var">cbuf0</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-491"></span><span>    </span><span id="local-6989586621679557401"><span class="annot"><span class="annottext">Maybe (Buffer Char)
</span><a href="#local-6989586621679557401"><span class="hs-identifier hs-var">mcbuf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO (Maybe (Buffer Char))
-&gt; (IOError -&gt; IO (Maybe (Buffer Char)))
-&gt; IO (Maybe (Buffer Char))
forall e a. Exception e =&gt; IO a -&gt; (e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.html#catch"><span class="hs-identifier hs-var">Exception.catch</span></a></span><span>
</span><span id="line-492"></span><span>        </span><span class="hs-special">(</span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679557400"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557400"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Internals.html#readTextDevice"><span class="hs-identifier hs-var">readTextDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557404"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557402"><span class="hs-identifier hs-var">cbuf0</span></a></span><span>
</span><span id="line-493"></span><span>            </span><span class="annot"><span class="annottext">Maybe (Buffer Char) -&gt; IO (Maybe (Buffer Char))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Maybe (Buffer Char)
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557400"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-494"></span><span>        </span><span class="hs-special">(</span><span class="hs-glyph">\</span><span id="local-6989586621679557399"><span class="annot"><span class="annottext">IOError
</span><a href="#local-6989586621679557399"><span class="hs-identifier hs-var">e</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; Bool
</span><a href="System.IO.Error.html#isEOFError"><span class="hs-identifier hs-var">isEOFError</span></a></span><span> </span><span class="annot"><span class="annottext">IOError
</span><a href="#local-6989586621679557399"><span class="hs-identifier hs-var">e</span></a></span><span>
</span><span id="line-495"></span><span>                  </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer Char) -&gt; IO (Maybe (Buffer Char))
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer Char)
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span>
</span><span id="line-496"></span><span>                  </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">IOError -&gt; IO (Maybe (Buffer Char))
forall a e. Exception e =&gt; e -&gt; a
</span><a href="GHC.Exception.html#throw"><span class="hs-identifier hs-var">throw</span></a></span><span> </span><span class="annot"><span class="annottext">IOError
</span><a href="#local-6989586621679557399"><span class="hs-identifier hs-var">e</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-497"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe (Buffer Char)
</span><a href="#local-6989586621679557401"><span class="hs-identifier hs-var">mcbuf</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-498"></span><span>      </span><span class="annot"><span class="annottext">Maybe (Buffer Char)
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">[Buffer Char] -&gt; IO [Buffer Char]
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557402"><span class="hs-identifier hs-var">cbuf0</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; [Buffer Char] -&gt; [Buffer Char]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557403"><span class="hs-identifier hs-var">cbufs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-499"></span><span>      </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679557398"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557398"><span class="hs-identifier hs-var">cbuf1</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; [Buffer Char] -&gt; Buffer Char -&gt; IO [Buffer Char]
</span><a href="GHC.IO.Handle.Text.html#strictReadLoop%27"><span class="hs-identifier hs-var">strictReadLoop'</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557404"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557403"><span class="hs-identifier hs-var">cbufs</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557398"><span class="hs-identifier hs-var">cbuf1</span></a></span><span>
</span><span id="line-500"></span><span>
</span><span id="line-501"></span><span class="hs-comment">-- If 'cbuf' is full, allocate a new buffer.</span><span>
</span><span id="line-502"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#strictReadLoop%27"><span class="hs-identifier hs-type">strictReadLoop'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-503"></span><span id="strictReadLoop%27"><span class="annot"><span class="annottext">strictReadLoop' :: Handle__ -&gt; [Buffer Char] -&gt; Buffer Char -&gt; IO [Buffer Char]
</span><a href="GHC.IO.Handle.Text.html#strictReadLoop%27"><span class="hs-identifier hs-var hs-var">strictReadLoop'</span></a></span></span><span> </span><span id="local-6989586621679557397"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557397"><span class="hs-identifier hs-var">handle_</span></a></span></span><span> </span><span id="local-6989586621679557396"><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557396"><span class="hs-identifier hs-var">cbufs</span></a></span></span><span> </span><span id="local-6989586621679557395"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557395"><span class="hs-identifier hs-var">cbuf</span></a></span></span><span>
</span><span id="line-504"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isFullCharBuffer"><span class="hs-identifier hs-var">isFullCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557395"><span class="hs-identifier hs-var">cbuf</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-505"></span><span>        </span><span id="local-6989586621679557393"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557393"><span class="hs-identifier hs-var">cbuf'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; BufferState -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Buffer.html#newCharBuffer"><span class="hs-identifier hs-var">newCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="GHC.IO.Handle.Internals.html#dEFAULT_CHAR_BUFFER_SIZE"><span class="hs-identifier hs-var">dEFAULT_CHAR_BUFFER_SIZE</span></a></span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#ReadBuffer"><span class="hs-identifier hs-var">ReadBuffer</span></a></span><span>
</span><span id="line-506"></span><span>        </span><span class="annot"><span class="annottext">Handle__ -&gt; [Buffer Char] -&gt; Buffer Char -&gt; IO [Buffer Char]
</span><a href="GHC.IO.Handle.Text.html#strictReadLoop"><span class="hs-identifier hs-var">strictReadLoop</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557397"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557395"><span class="hs-identifier hs-var">cbuf</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; [Buffer Char] -&gt; [Buffer Char]
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557396"><span class="hs-identifier hs-var">cbufs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557393"><span class="hs-identifier hs-var">cbuf'</span></a></span><span>
</span><span id="line-507"></span><span>    </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; [Buffer Char] -&gt; Buffer Char -&gt; IO [Buffer Char]
</span><a href="GHC.IO.Handle.Text.html#strictReadLoop"><span class="hs-identifier hs-var">strictReadLoop</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557397"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557396"><span class="hs-identifier hs-var">cbufs</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557395"><span class="hs-identifier hs-var">cbuf</span></a></span><span>
</span><span id="line-508"></span><span>
</span><span id="line-509"></span><span class="hs-comment">-- Lazily convert a list of buffers to a String. The buffers are</span><span>
</span><span id="line-510"></span><span class="hs-comment">-- in reverse order: the first buffer is the end of the String.</span><span>
</span><span id="line-511"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#lazyBuffersToString"><span class="hs-identifier hs-type">lazyBuffersToString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Newline"><span class="hs-identifier hs-type">Newline</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span>
</span><span id="line-512"></span><span id="lazyBuffersToString"><span class="annot"><span class="annottext">lazyBuffersToString :: Newline -&gt; [Buffer Char] -&gt; String -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#lazyBuffersToString"><span class="hs-identifier hs-var hs-var">lazyBuffersToString</span></a></span></span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="GHC.IO.Handle.Types.html#LF"><span class="hs-identifier hs-var">LF</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Buffer Char] -&gt; String -&gt; IO String
</span><a href="#local-6989586621679557388"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-513"></span><span>    </span><span id="local-6989586621679557388"><span class="annot"><span class="annottext">loop :: [Buffer Char] -&gt; String -&gt; IO String
</span><a href="#local-6989586621679557388"><span class="hs-identifier hs-var hs-var">loop</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span id="local-6989586621679557385"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557385"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557385"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-514"></span><span>    </span><span class="annot"><a href="#local-6989586621679557388"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557379"><span id="local-6989586621679557380"><span id="local-6989586621679557381"><span id="local-6989586621679557382"><span id="local-6989586621679557383"><span id="local-6989586621679557384"><span class="annot"><span class="annottext">Int
Word64
RawCharBuffer
BufferState
bufR :: Int
bufL :: Int
bufOffset :: Word64
bufSize :: Int
bufState :: BufferState
bufRaw :: RawCharBuffer
bufState :: forall e. Buffer e -&gt; BufferState
bufSize :: forall e. Buffer e -&gt; Int
bufOffset :: forall e. Buffer e -&gt; Word64
bufR :: forall e. Buffer e -&gt; Int
bufL :: forall e. Buffer e -&gt; Int
bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="#local-6989586621679557379"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span> </span><span id="local-6989586621679557378"><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557378"><span class="hs-identifier hs-var">cbufs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679557377"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557377"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-515"></span><span>        </span><span id="local-6989586621679557376"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557376"><span class="hs-identifier hs-var">s'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO String -&gt; IO String
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.Unsafe.html#unsafeInterleaveIO"><span class="hs-identifier hs-var">unsafeInterleaveIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; Int -&gt; String -&gt; IO String
</span><a href="GHC.IO.Handle.Text.html#unpack"><span class="hs-identifier hs-var">unpack</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557384"><span class="hs-identifier hs-var">bufRaw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557380"><span class="hs-identifier hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557379"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557377"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-516"></span><span>        </span><span class="annot"><span class="annottext">[Buffer Char] -&gt; String -&gt; IO String
</span><a href="#local-6989586621679557388"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557378"><span class="hs-identifier hs-var">cbufs</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557376"><span class="hs-identifier hs-var">s'</span></a></span><span>
</span><span id="line-517"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#lazyBuffersToString"><span class="hs-identifier hs-var">lazyBuffersToString</span></a></span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="GHC.IO.Handle.Types.html#CRLF"><span class="hs-identifier hs-var">CRLF</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Char -&gt; [Buffer Char] -&gt; String -&gt; IO String
</span><a href="#local-6989586621679557375"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\0'</span></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-518"></span><span>    </span><span id="local-6989586621679557375"><span class="annot"><span class="annottext">loop :: Char -&gt; [Buffer Char] -&gt; String -&gt; IO String
</span><a href="#local-6989586621679557375"><span class="hs-identifier hs-var hs-var">loop</span></a></span></span><span> </span><span id="local-6989586621679557359"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557359"><span class="hs-identifier hs-var">before</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span id="local-6989586621679557358"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557358"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557358"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-519"></span><span>    </span><span class="annot"><a href="#local-6989586621679557375"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span id="local-6989586621679557357"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557357"><span class="hs-identifier hs-var">before</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557351"><span id="local-6989586621679557352"><span id="local-6989586621679557353"><span id="local-6989586621679557354"><span id="local-6989586621679557355"><span id="local-6989586621679557356"><span class="annot"><span class="annottext">Int
Word64
RawCharBuffer
BufferState
bufR :: Int
bufL :: Int
bufOffset :: Word64
bufSize :: Int
bufState :: BufferState
bufRaw :: RawCharBuffer
bufState :: forall e. Buffer e -&gt; BufferState
bufSize :: forall e. Buffer e -&gt; Int
bufOffset :: forall e. Buffer e -&gt; Word64
bufR :: forall e. Buffer e -&gt; Int
bufL :: forall e. Buffer e -&gt; Int
bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="#local-6989586621679557351"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span> </span><span id="local-6989586621679557350"><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557350"><span class="hs-identifier hs-var">cbufs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679557349"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557349"><span class="hs-identifier hs-var">s</span></a></span></span><span>
</span><span id="line-520"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557352"><span class="hs-identifier hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557351"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Char -&gt; [Buffer Char] -&gt; String -&gt; IO String
</span><a href="#local-6989586621679557375"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557357"><span class="hs-identifier hs-var">before</span></a></span><span> </span><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557350"><span class="hs-identifier hs-var">cbufs</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557349"><span class="hs-identifier hs-var">s</span></a></span><span>  </span><span class="hs-comment">-- skip empty buffers</span><span>
</span><span id="line-521"></span><span>        </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-522"></span><span>            </span><span class="hs-comment">-- When a CRLF is broken across two buffers, we already have a newline</span><span>
</span><span id="line-523"></span><span>            </span><span class="hs-comment">-- from decoding the LF, so we ignore the CR in the current buffer.</span><span>
</span><span id="line-524"></span><span>            </span><span id="local-6989586621679557348"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557348"><span class="hs-identifier hs-var">s1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557357"><span class="hs-identifier hs-var">before</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span>
</span><span id="line-525"></span><span>                     </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557349"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-526"></span><span>                     </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-527"></span><span>                       </span><span class="hs-comment">-- We restore trailing CR not followed by LF.</span><span>
</span><span id="line-528"></span><span>                       </span><span id="local-6989586621679557347"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557347"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; IO Char
</span><a href="GHC.IO.Buffer.html#peekCharBuf"><span class="hs-identifier hs-var">peekCharBuf</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557356"><span class="hs-identifier hs-var">bufRaw</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557351"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span class="hs-special">)</span><span>
</span><span id="line-529"></span><span>                       </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557347"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\r'</span></span><span>
</span><span id="line-530"></span><span>                          </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\r'</span></span><span> </span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557349"><span class="hs-identifier hs-var">s</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-531"></span><span>                          </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557349"><span class="hs-identifier hs-var">s</span></a></span><span>
</span><span id="line-532"></span><span>            </span><span id="local-6989586621679557345"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557345"><span class="hs-identifier hs-var">s2</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IO String -&gt; IO String
forall a. IO a -&gt; IO a
</span><a href="GHC.IO.Unsafe.html#unsafeInterleaveIO"><span class="hs-identifier hs-var">unsafeInterleaveIO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-keyword">do</span><span>
</span><span id="line-533"></span><span>                </span><span class="hs-special">(</span><span id="local-6989586621679557344"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557344"><span class="hs-identifier hs-var">s2</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; Int -&gt; String -&gt; IO (String, Int)
</span><a href="GHC.IO.Handle.Text.html#unpack_nl"><span class="hs-identifier hs-var">unpack_nl</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557356"><span class="hs-identifier hs-var">bufRaw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557352"><span class="hs-identifier hs-var">bufL</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557351"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557348"><span class="hs-identifier hs-var">s1</span></a></span><span>
</span><span id="line-534"></span><span>                </span><span class="annot"><span class="annottext">String -&gt; IO String
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557344"><span class="hs-identifier hs-var">s2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-535"></span><span>            </span><span id="local-6989586621679557343"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557343"><span class="hs-identifier hs-var">c0</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; IO Char
</span><a href="GHC.IO.Buffer.html#peekCharBuf"><span class="hs-identifier hs-var">peekCharBuf</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557356"><span class="hs-identifier hs-var">bufRaw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557352"><span class="hs-identifier hs-var">bufL</span></a></span><span>
</span><span id="line-536"></span><span>            </span><span class="annot"><span class="annottext">Char -&gt; [Buffer Char] -&gt; String -&gt; IO String
</span><a href="#local-6989586621679557375"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557343"><span class="hs-identifier hs-var">c0</span></a></span><span> </span><span class="annot"><span class="annottext">[Buffer Char]
</span><a href="#local-6989586621679557350"><span class="hs-identifier hs-var">cbufs</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557345"><span class="hs-identifier hs-var">s2</span></a></span><span>
</span><span id="line-537"></span><span>
</span><span id="line-538"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-539"></span><span class="hs-comment">-- hPutChar</span><span>
</span><span id="line-540"></span><span>
</span><span id="line-541"></span><span class="hs-comment">-- | Computation 'hPutChar' @hdl ch@ writes the character @ch@ to the</span><span>
</span><span id="line-542"></span><span class="hs-comment">-- file or channel managed by @hdl@.  Characters may be buffered if</span><span>
</span><span id="line-543"></span><span class="hs-comment">-- buffering is enabled for @hdl@.</span><span>
</span><span id="line-544"></span><span class="hs-comment">--</span><span>
</span><span id="line-545"></span><span class="hs-comment">-- This operation may fail with:</span><span>
</span><span id="line-546"></span><span class="hs-comment">--</span><span>
</span><span id="line-547"></span><span class="hs-comment">--  * 'isFullError' if the device is full; or</span><span>
</span><span id="line-548"></span><span class="hs-comment">--</span><span>
</span><span id="line-549"></span><span class="hs-comment">--  * 'isPermissionError' if another system resource limit would be exceeded.</span><span>
</span><span id="line-550"></span><span>
</span><span id="line-551"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutChar"><span class="hs-identifier hs-type">hPutChar</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-552"></span><span id="hPutChar"><span class="annot"><span class="annottext">hPutChar :: Handle -&gt; Char -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutChar"><span class="hs-identifier hs-var hs-var">hPutChar</span></a></span></span><span> </span><span id="local-6989586621679557342"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557342"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span id="local-6989586621679557341"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557341"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-553"></span><span>    </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557341"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; IO () -&gt; IO ()
</span><a href="../../ghc-prim/src/GHC.Prim.html#seq"><span class="hs-operator hs-var">`seq`</span></a></span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-554"></span><span>    </span><span class="annot"><span class="annottext">String -&gt; Handle -&gt; (Handle__ -&gt; IO ()) -&gt; IO ()
forall a. String -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantWritableHandle"><span class="hs-identifier hs-var">wantWritableHandle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hPutChar&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557342"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO ()) -&gt; IO ()) -&gt; (Handle__ -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679557339"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557339"><span class="hs-identifier hs-var">handle_</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-555"></span><span>     </span><span class="annot"><span class="annottext">Handle__ -&gt; Char -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutcBuffered"><span class="hs-identifier hs-var">hPutcBuffered</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557339"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557341"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-556"></span><span>
</span><span id="line-557"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutcBuffered"><span class="hs-identifier hs-type">hPutcBuffered</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-558"></span><span id="hPutcBuffered"><span class="annot"><span class="annottext">hPutcBuffered :: Handle__ -&gt; Char -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutcBuffered"><span class="hs-identifier hs-var hs-var">hPutcBuffered</span></a></span></span><span> </span><span id="local-6989586621679557337"><span class="annot"><span class="annottext">handle_ :: Handle__
</span><a href="#local-6989586621679557337"><span class="hs-identifier hs-var">handle_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557310"><span id="local-6989586621679557311"><span id="local-6989586621679557312"><span id="local-6989586621679557313"><span id="local-6989586621679557314"><span id="local-6989586621679557315"><span id="local-6989586621679557316"><span id="local-6989586621679557317"><span id="local-6989586621679557318"><span id="local-6989586621679557319"><span id="local-6989586621679557320"><span id="local-6989586621679557321"><span id="local-6989586621679557322"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679557310"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span id="local-6989586621679557309"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557309"><span class="hs-identifier hs-var">c</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-559"></span><span>  </span><span id="local-6989586621679557308"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557308"><span class="hs-identifier hs-var">buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557317"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-560"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557309"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span>
</span><span id="line-561"></span><span>     </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679557307"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557307"><span class="hs-identifier hs-var">buf1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="#local-6989586621679557311"><span class="hs-identifier hs-var">haOutputNL</span></a></span><span> </span><span class="annot"><span class="annottext">Newline -&gt; Newline -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="GHC.IO.Handle.Types.html#CRLF"><span class="hs-identifier hs-var">CRLF</span></a></span><span>
</span><span id="line-562"></span><span>                        </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-563"></span><span>                          </span><span id="local-6989586621679557306"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557306"><span class="hs-identifier hs-var">buf1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Char -&gt; IO (Buffer Char)
</span><a href="#local-6989586621679557305"><span class="hs-identifier hs-var">putc</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557308"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\r'</span></span><span>
</span><span id="line-564"></span><span>                          </span><span class="annot"><span class="annottext">Buffer Char -&gt; Char -&gt; IO (Buffer Char)
</span><a href="#local-6989586621679557305"><span class="hs-identifier hs-var">putc</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557306"><span class="hs-identifier hs-var">buf1</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span>
</span><span id="line-565"></span><span>                        </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-566"></span><span>                          </span><span class="annot"><span class="annottext">Buffer Char -&gt; Char -&gt; IO (Buffer Char)
</span><a href="#local-6989586621679557305"><span class="hs-identifier hs-var">putc</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557308"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span>
</span><span id="line-567"></span><span>             </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#writeCharBuffer"><span class="hs-identifier hs-var">writeCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557337"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557307"><span class="hs-identifier hs-var">buf1</span></a></span><span>
</span><span id="line-568"></span><span>             </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557302"><span class="hs-identifier hs-var">is_line</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushByteWriteBuffer"><span class="hs-identifier hs-var">flushByteWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557337"><span class="hs-identifier hs-var">handle_</span></a></span><span>
</span><span id="line-569"></span><span>      </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-570"></span><span>          </span><span id="local-6989586621679557300"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557300"><span class="hs-identifier hs-var">buf1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; Char -&gt; IO (Buffer Char)
</span><a href="#local-6989586621679557305"><span class="hs-identifier hs-var">putc</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557308"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557309"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-571"></span><span>          </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#writeCharBuffer"><span class="hs-identifier hs-var">writeCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557337"><span class="hs-identifier hs-var">handle_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557300"><span class="hs-identifier hs-var">buf1</span></a></span><span>
</span><span id="line-572"></span><span>          </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-573"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-574"></span><span>    </span><span id="local-6989586621679557302"><span class="annot"><span class="annottext">is_line :: Bool
</span><a href="#local-6989586621679557302"><span class="hs-identifier hs-var hs-var">is_line</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679557319"><span class="hs-identifier hs-var">haBufferMode</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-575"></span><span>                </span><span class="annot"><span class="annottext">BufferMode
</span><a href="GHC.IO.Handle.Types.html#LineBuffering"><span class="hs-identifier hs-var">LineBuffering</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-576"></span><span>                </span><span class="annot"><span class="annottext">BufferMode
</span><span class="hs-identifier">_</span></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-577"></span><span>
</span><span id="line-578"></span><span>    </span><span id="local-6989586621679557305"><span class="annot"><span class="annottext">putc :: Buffer Char -&gt; Char -&gt; IO (Buffer Char)
</span><a href="#local-6989586621679557305"><span class="hs-identifier hs-var hs-var">putc</span></a></span></span><span> </span><span id="local-6989586621679557295"><span class="annot"><span class="annottext">buf :: Buffer Char
</span><a href="#local-6989586621679557295"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557294"><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557294"><span class="hs-identifier hs-var">raw</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557293"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557293"><span class="hs-identifier hs-var">w</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span id="local-6989586621679557292"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557292"><span class="hs-identifier hs-var">c'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-579"></span><span>       </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;putc: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557295"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-580"></span><span>       </span><span id="local-6989586621679557290"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557290"><span class="hs-identifier hs-var">w'</span></a></span></span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; Char -&gt; IO Int
</span><a href="GHC.IO.Buffer.html#writeCharBuf"><span class="hs-identifier hs-var">writeCharBuf</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557294"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557293"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557292"><span class="hs-identifier hs-var">c'</span></a></span><span>
</span><span id="line-581"></span><span>       </span><span class="annot"><span class="annottext">Buffer Char -&gt; IO (Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557295"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557290"><span class="hs-identifier hs-var">w'</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-582"></span><span>
</span><span id="line-583"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-584"></span><span class="hs-comment">-- hPutStr</span><span>
</span><span id="line-585"></span><span>
</span><span id="line-586"></span><span class="hs-comment">-- We go to some trouble to avoid keeping the handle locked while we're</span><span>
</span><span id="line-587"></span><span class="hs-comment">-- evaluating the string argument to hPutStr, in case doing so triggers another</span><span>
</span><span id="line-588"></span><span class="hs-comment">-- I/O operation on the same handle which would lead to deadlock.  The classic</span><span>
</span><span id="line-589"></span><span class="hs-comment">-- case is</span><span>
</span><span id="line-590"></span><span class="hs-comment">--</span><span>
</span><span id="line-591"></span><span class="hs-comment">--              putStr (trace &quot;hello&quot; &quot;world&quot;)</span><span>
</span><span id="line-592"></span><span class="hs-comment">--</span><span>
</span><span id="line-593"></span><span class="hs-comment">-- so the basic scheme is this:</span><span>
</span><span id="line-594"></span><span class="hs-comment">--</span><span>
</span><span id="line-595"></span><span class="hs-comment">--      * copy the string into a fresh buffer,</span><span>
</span><span id="line-596"></span><span class="hs-comment">--      * &quot;commit&quot; the buffer to the handle.</span><span>
</span><span id="line-597"></span><span class="hs-comment">--</span><span>
</span><span id="line-598"></span><span class="hs-comment">-- Committing may involve simply copying the contents of the new</span><span>
</span><span id="line-599"></span><span class="hs-comment">-- buffer into the handle's buffer, flushing one or both buffers, or</span><span>
</span><span id="line-600"></span><span class="hs-comment">-- maybe just swapping the buffers over (if the handle's buffer was</span><span>
</span><span id="line-601"></span><span class="hs-comment">-- empty).  See commitBuffer below.</span><span>
</span><span id="line-602"></span><span>
</span><span id="line-603"></span><span class="hs-comment">-- | Computation 'hPutStr' @hdl s@ writes the string</span><span>
</span><span id="line-604"></span><span class="hs-comment">-- @s@ to the file or channel managed by @hdl@.</span><span>
</span><span id="line-605"></span><span class="hs-comment">--</span><span>
</span><span id="line-606"></span><span class="hs-comment">-- This operation may fail with:</span><span>
</span><span id="line-607"></span><span class="hs-comment">--</span><span>
</span><span id="line-608"></span><span class="hs-comment">--  * 'isFullError' if the device is full; or</span><span>
</span><span id="line-609"></span><span class="hs-comment">--</span><span>
</span><span id="line-610"></span><span class="hs-comment">--  * 'isPermissionError' if another system resource limit would be exceeded.</span><span>
</span><span id="line-611"></span><span>
</span><span id="line-612"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutStr"><span class="hs-identifier hs-type">hPutStr</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-613"></span><span id="hPutStr"><span class="annot"><span class="annottext">hPutStr :: Handle -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutStr"><span class="hs-identifier hs-var hs-var">hPutStr</span></a></span></span><span> </span><span id="local-6989586621679557289"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557289"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span id="local-6989586621679557288"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557288"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; Bool -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutStr%27"><span class="hs-identifier hs-var">hPutStr'</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557289"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557288"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-614"></span><span>
</span><span id="line-615"></span><span class="hs-comment">-- | The same as 'hPutStr', but adds a newline character.</span><span>
</span><span id="line-616"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutStrLn"><span class="hs-identifier hs-type">hPutStrLn</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-617"></span><span id="hPutStrLn"><span class="annot"><span class="annottext">hPutStrLn :: Handle -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutStrLn"><span class="hs-identifier hs-var hs-var">hPutStrLn</span></a></span></span><span> </span><span id="local-6989586621679557286"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557286"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span id="local-6989586621679557285"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557285"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; Bool -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutStr%27"><span class="hs-identifier hs-var">hPutStr'</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557286"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557285"><span class="hs-identifier hs-var">str</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-618"></span><span>  </span><span class="hs-comment">-- An optimisation: we treat hPutStrLn specially, to avoid the</span><span>
</span><span id="line-619"></span><span>  </span><span class="hs-comment">-- overhead of a single putChar '\n', which is quite high now that we</span><span>
</span><span id="line-620"></span><span>  </span><span class="hs-comment">-- have to encode eagerly.</span><span>
</span><span id="line-621"></span><span>
</span><span id="line-622"></span><span class="hs-pragma">{-# NOINLINE</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutStr%27"><span class="hs-pragma hs-type">hPutStr'</span></a></span><span> </span><span class="hs-pragma">#-}</span><span>
</span><span id="line-623"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutStr%27"><span class="hs-identifier hs-type">hPutStr'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-624"></span><span id="hPutStr%27"><span class="annot"><span class="annottext">hPutStr' :: Handle -&gt; String -&gt; Bool -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutStr%27"><span class="hs-identifier hs-var hs-var">hPutStr'</span></a></span></span><span> </span><span id="local-6989586621679557284"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557284"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span id="local-6989586621679557283"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557283"><span class="hs-identifier hs-var">str</span></a></span></span><span> </span><span id="local-6989586621679557282"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557282"><span class="hs-identifier hs-var">add_nl</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-625"></span><span>  </span><span class="hs-keyword">do</span><span>
</span><span id="line-626"></span><span>    </span><span class="hs-special">(</span><span id="local-6989586621679557281"><span class="annot"><span class="annottext">(BufferMode, Buffer Char)
</span><a href="#local-6989586621679557281"><span class="hs-identifier hs-var">buffer_mode</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679557280"><span class="annot"><span class="annottext">Newline
</span><a href="#local-6989586621679557280"><span class="hs-identifier hs-var">nl</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span>
</span><span id="line-627"></span><span>         </span><span class="annot"><span class="annottext">String
-&gt; Handle
-&gt; (Handle__ -&gt; IO ((BufferMode, Buffer Char), Newline))
-&gt; IO ((BufferMode, Buffer Char), Newline)
forall a. String -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantWritableHandle"><span class="hs-identifier hs-var">wantWritableHandle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hPutStr&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557284"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO ((BufferMode, Buffer Char), Newline))
 -&gt; IO ((BufferMode, Buffer Char), Newline))
-&gt; (Handle__ -&gt; IO ((BufferMode, Buffer Char), Newline))
-&gt; IO ((BufferMode, Buffer Char), Newline)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679557279"><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557279"><span class="hs-identifier hs-var">h_</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-628"></span><span>                       </span><span id="local-6989586621679557278"><span class="annot"><span class="annottext">(BufferMode, Buffer Char)
</span><a href="#local-6989586621679557278"><span class="hs-identifier hs-var">bmode</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO (BufferMode, Buffer Char)
</span><a href="GHC.IO.Handle.Text.html#getSpareBuffer"><span class="hs-identifier hs-var">getSpareBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557279"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-629"></span><span>                       </span><span class="annot"><span class="annottext">((BufferMode, Buffer Char), Newline)
-&gt; IO ((BufferMode, Buffer Char), Newline)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(BufferMode, Buffer Char)
</span><a href="#local-6989586621679557278"><span class="hs-identifier hs-var">bmode</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Newline
</span><a href="GHC.IO.Handle.Types.html#haOutputNL"><span class="hs-identifier hs-var hs-var">haOutputNL</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557279"><span class="hs-identifier hs-var">h_</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-630"></span><span>
</span><span id="line-631"></span><span>    </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">(BufferMode, Buffer Char)
</span><a href="#local-6989586621679557281"><span class="hs-identifier hs-var">buffer_mode</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-632"></span><span>       </span><span class="hs-special">(</span><span class="annot"><span class="annottext">BufferMode
</span><a href="GHC.IO.Handle.Types.html#NoBuffering"><span class="hs-identifier hs-var">NoBuffering</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-633"></span><span>            </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutChars"><span class="hs-identifier hs-var">hPutChars</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557284"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557283"><span class="hs-identifier hs-var">str</span></a></span><span>        </span><span class="hs-comment">-- v. slow, but we don't care</span><span>
</span><span id="line-634"></span><span>            </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557282"><span class="hs-identifier hs-var">add_nl</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Handle -&gt; Char -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutChar"><span class="hs-identifier hs-var">hPutChar</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557284"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span>
</span><span id="line-635"></span><span>       </span><span class="hs-special">(</span><span class="annot"><span class="annottext">BufferMode
</span><a href="GHC.IO.Handle.Types.html#LineBuffering"><span class="hs-identifier hs-var">LineBuffering</span></a></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679557274"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557274"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-636"></span><span>            </span><span class="annot"><span class="annottext">Handle -&gt; Bool -&gt; Bool -&gt; Newline -&gt; Buffer Char -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#writeBlocks"><span class="hs-identifier hs-var">writeBlocks</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557284"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>  </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557282"><span class="hs-identifier hs-var">add_nl</span></a></span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="#local-6989586621679557280"><span class="hs-identifier hs-var">nl</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557274"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557283"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-637"></span><span>       </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#BlockBuffering"><span class="hs-identifier hs-type">BlockBuffering</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Int
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621679557271"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557271"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-638"></span><span>            </span><span class="annot"><span class="annottext">Handle -&gt; Bool -&gt; Bool -&gt; Newline -&gt; Buffer Char -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#writeBlocks"><span class="hs-identifier hs-var">writeBlocks</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557284"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557282"><span class="hs-identifier hs-var">add_nl</span></a></span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="#local-6989586621679557280"><span class="hs-identifier hs-var">nl</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557271"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557283"><span class="hs-identifier hs-var">str</span></a></span><span>
</span><span id="line-639"></span><span>
</span><span id="line-640"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutChars"><span class="hs-identifier hs-type">hPutChars</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-641"></span><span id="hPutChars"><span class="annot"><span class="annottext">hPutChars :: Handle -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutChars"><span class="hs-identifier hs-var hs-var">hPutChars</span></a></span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-642"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutChars"><span class="hs-identifier hs-var">hPutChars</span></a></span><span> </span><span id="local-6989586621679557270"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557270"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679557269"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557269"><span class="hs-identifier hs-var">c</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679557268"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557268"><span class="hs-identifier hs-var">cs</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; Char -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutChar"><span class="hs-identifier hs-var">hPutChar</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557270"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557269"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">IO () -&gt; IO () -&gt; IO ()
forall (m :: * -&gt; *) a b. Monad m =&gt; m a -&gt; m b -&gt; m b
</span><a href="GHC.Base.html#%3E%3E"><span class="hs-operator hs-var">&gt;&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutChars"><span class="hs-identifier hs-var">hPutChars</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557270"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557268"><span class="hs-identifier hs-var">cs</span></a></span><span>
</span><span id="line-643"></span><span>
</span><span id="line-644"></span><span class="hs-comment">-- Buffer offset is always zero.</span><span>
</span><span id="line-645"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#getSpareBuffer"><span class="hs-identifier hs-type">getSpareBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Handle.Types.html#BufferMode"><span class="hs-identifier hs-type">BufferMode</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-646"></span><span id="getSpareBuffer"><span class="annot"><span class="annottext">getSpareBuffer :: Handle__ -&gt; IO (BufferMode, Buffer Char)
</span><a href="GHC.IO.Handle.Text.html#getSpareBuffer"><span class="hs-identifier hs-var hs-var">getSpareBuffer</span></a></span></span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span class="annot"><span class="annottext">haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
</span><a href="GHC.IO.Handle.Types.html#haCharBuffer"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557256"><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557256"><span class="hs-identifier hs-var">ref</span></a></span></span><span class="hs-special">,</span><span>
</span><span id="line-647"></span><span>                        </span><span class="annot"><span class="annottext">haBuffers :: Handle__ -&gt; IORef (BufferList Char)
</span><a href="GHC.IO.Handle.Types.html#haBuffers"><span class="hs-identifier hs-var">haBuffers</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557255"><span class="annot"><span class="annottext">IORef (BufferList Char)
</span><a href="#local-6989586621679557255"><span class="hs-identifier hs-var">spare_ref</span></a></span></span><span class="hs-special">,</span><span>
</span><span id="line-648"></span><span>                        </span><span class="annot"><span class="annottext">haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="GHC.IO.Handle.Types.html#haBufferMode"><span class="hs-identifier hs-var">haBufferMode</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557254"><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679557254"><span class="hs-identifier hs-var">mode</span></a></span></span><span class="hs-special">}</span><span>
</span><span id="line-649"></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-650"></span><span>   </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679557254"><span class="hs-identifier hs-var">mode</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-651"></span><span>     </span><span class="annot"><span class="annottext">BufferMode
</span><a href="GHC.IO.Handle.Types.html#NoBuffering"><span class="hs-identifier hs-var">NoBuffering</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">(BufferMode, Buffer Char) -&gt; IO (BufferMode, Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679557254"><span class="hs-identifier hs-var">mode</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; Buffer Char
forall a. String -&gt; a
</span><a href="GHC.Err.html#errorWithoutStackTrace"><span class="hs-identifier hs-var">errorWithoutStackTrace</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;no buffer!&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-652"></span><span>     </span><span class="annot"><span class="annottext">BufferMode
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-653"></span><span>          </span><span id="local-6989586621679557252"><span class="annot"><span class="annottext">BufferList Char
</span><a href="#local-6989586621679557252"><span class="hs-identifier hs-var">bufs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (BufferList Char) -&gt; IO (BufferList Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (BufferList Char)
</span><a href="#local-6989586621679557255"><span class="hs-identifier hs-var">spare_ref</span></a></span><span>
</span><span id="line-654"></span><span>          </span><span id="local-6989586621679557251"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557251"><span class="hs-identifier hs-var">buf</span></a></span></span><span>  </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557256"><span class="hs-identifier hs-var">ref</span></a></span><span>
</span><span id="line-655"></span><span>          </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">BufferList Char
</span><a href="#local-6989586621679557252"><span class="hs-identifier hs-var">bufs</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-656"></span><span>            </span><span class="annot"><a href="GHC.IO.Handle.Types.html#BufferListCons"><span class="hs-identifier hs-type">BufferListCons</span></a></span><span> </span><span id="local-6989586621679557249"><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557249"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span id="local-6989586621679557248"><span class="annot"><span class="annottext">BufferList Char
</span><a href="#local-6989586621679557248"><span class="hs-identifier hs-var">rest</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-657"></span><span>                </span><span class="annot"><span class="annottext">IORef (BufferList Char) -&gt; BufferList Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (BufferList Char)
</span><a href="#local-6989586621679557255"><span class="hs-identifier hs-var">spare_ref</span></a></span><span> </span><span class="annot"><span class="annottext">BufferList Char
</span><a href="#local-6989586621679557248"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-658"></span><span>                </span><span class="annot"><span class="annottext">(BufferMode, Buffer Char) -&gt; IO (BufferMode, Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679557254"><span class="hs-identifier hs-var">mode</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; BufferState -&gt; Buffer Char
forall e. RawBuffer e -&gt; Int -&gt; BufferState -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#emptyBuffer"><span class="hs-identifier hs-var">emptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557249"><span class="hs-identifier hs-var">b</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var hs-var">bufSize</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557251"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-659"></span><span>            </span><span class="annot"><span class="annottext">BufferList Char
</span><a href="GHC.IO.Handle.Types.html#BufferListNil"><span class="hs-identifier hs-var">BufferListNil</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-660"></span><span>                </span><span id="local-6989586621679557244"><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557244"><span class="hs-identifier hs-var">new_buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Int -&gt; BufferState -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Buffer.html#newCharBuffer"><span class="hs-identifier hs-var">newCharBuffer</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Char -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var hs-var">bufSize</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557251"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span>
</span><span id="line-661"></span><span>                </span><span class="annot"><span class="annottext">(BufferMode, Buffer Char) -&gt; IO (BufferMode, Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679557254"><span class="hs-identifier hs-var">mode</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557244"><span class="hs-identifier hs-var">new_buf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-662"></span><span>
</span><span id="line-663"></span><span>
</span><span id="line-664"></span><span class="hs-comment">-- NB. performance-critical code: eyeball the Core.</span><span>
</span><span id="line-665"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#writeBlocks"><span class="hs-identifier hs-type">writeBlocks</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Newline"><span class="hs-identifier hs-type">Newline</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBufElem"><span class="hs-identifier hs-type">CharBufElem</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-666"></span><span id="writeBlocks"><span class="annot"><span class="annottext">writeBlocks :: Handle -&gt; Bool -&gt; Bool -&gt; Newline -&gt; Buffer Char -&gt; String -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#writeBlocks"><span class="hs-identifier hs-var hs-var">writeBlocks</span></a></span></span><span> </span><span id="local-6989586621679557242"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557242"><span class="hs-identifier hs-var">hdl</span></a></span></span><span> </span><span id="local-6989586621679557241"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557241"><span class="hs-identifier hs-var">line_buffered</span></a></span></span><span> </span><span id="local-6989586621679557240"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557240"><span class="hs-identifier hs-var">add_nl</span></a></span></span><span> </span><span id="local-6989586621679557239"><span class="annot"><span class="annottext">Newline
</span><a href="#local-6989586621679557239"><span class="hs-identifier hs-var">nl</span></a></span></span><span>
</span><span id="line-667"></span><span>            </span><span id="local-6989586621679557238"><span class="annot"><span class="annottext">buf :: Buffer Char
</span><a href="#local-6989586621679557238"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557237"><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557237"><span class="hs-identifier hs-var">raw</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557236"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557236"><span class="hs-identifier hs-var">len</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span id="local-6989586621679557235"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557235"><span class="hs-identifier hs-var">s</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-668"></span><span>  </span><span class="hs-keyword">let</span><span>
</span><span id="line-669"></span><span>   </span><span class="annot"><a href="#local-6989586621679557234"><span class="hs-identifier hs-type">shoveString</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Char"><span class="hs-identifier hs-type">Char</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-670"></span><span>   </span><span id="local-6989586621679557234"><span class="annot"><span class="annottext">shoveString :: Int -&gt; String -&gt; String -&gt; IO ()
</span><a href="#local-6989586621679557234"><span class="hs-identifier hs-var hs-var">shoveString</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557233"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557233"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-671"></span><span>        </span><span class="annot"><span class="annottext">Handle -&gt; RawCharBuffer -&gt; Int -&gt; Int -&gt; Bool -&gt; Bool -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#commitBuffer"><span class="hs-identifier hs-var">commitBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557242"><span class="hs-identifier hs-var">hdl</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557237"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557236"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557233"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-comment">{-no flush-}</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-comment">{-release-}</span><span>
</span><span id="line-672"></span><span>   </span><span class="annot"><a href="#local-6989586621679557234"><span class="hs-identifier hs-var">shoveString</span></a></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557231"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557231"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span id="local-6989586621679557230"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557230"><span class="hs-identifier hs-var">rest</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-673"></span><span>        </span><span class="annot"><span class="annottext">Int -&gt; String -&gt; String -&gt; IO ()
</span><a href="#local-6989586621679557234"><span class="hs-identifier hs-var">shoveString</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557231"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557230"><span class="hs-identifier hs-var">rest</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span>
</span><span id="line-674"></span><span>   </span><span class="annot"><a href="#local-6989586621679557234"><span class="hs-identifier hs-var">shoveString</span></a></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557229"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557229"><span class="hs-identifier hs-var">n</span></a></span></span><span> </span><span class="hs-special">(</span><span id="local-6989586621679557228"><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557228"><span class="hs-identifier hs-var">c</span></a></span></span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-type">:</span></a></span><span id="local-6989586621679557227"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557227"><span class="hs-identifier hs-var">cs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679557226"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557226"><span class="hs-identifier hs-var">rest</span></a></span></span><span>
</span><span id="line-675"></span><span>     </span><span class="hs-comment">-- n+1 so we have enough room to write '\r\n' if necessary</span><span>
</span><span id="line-676"></span><span>     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557229"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">1</span></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E%3D"><span class="hs-operator hs-var">&gt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557236"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-677"></span><span>        </span><span class="annot"><span class="annottext">Handle -&gt; RawCharBuffer -&gt; Int -&gt; Int -&gt; Bool -&gt; Bool -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#commitBuffer"><span class="hs-identifier hs-var">commitBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557242"><span class="hs-identifier hs-var">hdl</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557237"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557236"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557229"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span class="hs-comment">{-flush-}</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-678"></span><span>        </span><span class="annot"><span class="annottext">Int -&gt; String -&gt; String -&gt; IO ()
</span><a href="#local-6989586621679557234"><span class="hs-identifier hs-var">shoveString</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557228"><span class="hs-identifier hs-var">c</span></a></span><span class="annot"><span class="annottext">Char -&gt; String -&gt; String
forall a. a -&gt; [a] -&gt; [a]
</span><a href="../../ghc-prim/src/GHC.Types.html#%3A"><span class="hs-glyph hs-var">:</span></a></span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557227"><span class="hs-identifier hs-var">cs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557226"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-679"></span><span>     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557228"><span class="hs-identifier hs-var">c</span></a></span><span> </span><span class="annot"><span class="annottext">Char -&gt; Char -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span>  </span><span class="hs-glyph">=</span><span>  </span><span class="hs-keyword">do</span><span>
</span><span id="line-680"></span><span>        </span><span id="local-6989586621679557225"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557225"><span class="hs-identifier hs-var">n'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="#local-6989586621679557239"><span class="hs-identifier hs-var">nl</span></a></span><span> </span><span class="annot"><span class="annottext">Newline -&gt; Newline -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Newline
</span><a href="GHC.IO.Handle.Types.html#CRLF"><span class="hs-identifier hs-var">CRLF</span></a></span><span>
</span><span id="line-681"></span><span>                 </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-682"></span><span>                    </span><span id="local-6989586621679557224"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557224"><span class="hs-identifier hs-var">n1</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; Char -&gt; IO Int
</span><a href="GHC.IO.Buffer.html#writeCharBuf"><span class="hs-identifier hs-var">writeCharBuf</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557237"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557229"><span class="hs-identifier hs-var">n</span></a></span><span>  </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\r'</span></span><span>
</span><span id="line-683"></span><span>                    </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; Char -&gt; IO Int
</span><a href="GHC.IO.Buffer.html#writeCharBuf"><span class="hs-identifier hs-var">writeCharBuf</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557237"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557224"><span class="hs-identifier hs-var">n1</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><span class="hs-char">'\n'</span></span><span>
</span><span id="line-684"></span><span>                 </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-685"></span><span>                    </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; Char -&gt; IO Int
</span><a href="GHC.IO.Buffer.html#writeCharBuf"><span class="hs-identifier hs-var">writeCharBuf</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557237"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557229"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557228"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-686"></span><span>        </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557241"><span class="hs-identifier hs-var">line_buffered</span></a></span><span>
</span><span id="line-687"></span><span>           </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-688"></span><span>                </span><span class="hs-comment">-- end of line, so write and flush</span><span>
</span><span id="line-689"></span><span>               </span><span class="annot"><span class="annottext">Handle -&gt; RawCharBuffer -&gt; Int -&gt; Int -&gt; Bool -&gt; Bool -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#commitBuffer"><span class="hs-identifier hs-var">commitBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557242"><span class="hs-identifier hs-var">hdl</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557237"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557236"><span class="hs-identifier hs-var">len</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557225"><span class="hs-identifier hs-var">n'</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span class="hs-comment">{-flush-}</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-690"></span><span>               </span><span class="annot"><span class="annottext">Int -&gt; String -&gt; String -&gt; IO ()
</span><a href="#local-6989586621679557234"><span class="hs-identifier hs-var">shoveString</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557227"><span class="hs-identifier hs-var">cs</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557226"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-691"></span><span>           </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-692"></span><span>               </span><span class="annot"><span class="annottext">Int -&gt; String -&gt; String -&gt; IO ()
</span><a href="#local-6989586621679557234"><span class="hs-identifier hs-var">shoveString</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557225"><span class="hs-identifier hs-var">n'</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557227"><span class="hs-identifier hs-var">cs</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557226"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-693"></span><span>     </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-694"></span><span>        </span><span id="local-6989586621679557223"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557223"><span class="hs-identifier hs-var">n'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RawCharBuffer -&gt; Int -&gt; Char -&gt; IO Int
</span><a href="GHC.IO.Buffer.html#writeCharBuf"><span class="hs-identifier hs-var">writeCharBuf</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557237"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557229"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Char
</span><a href="#local-6989586621679557228"><span class="hs-identifier hs-var">c</span></a></span><span>
</span><span id="line-695"></span><span>        </span><span class="annot"><span class="annottext">Int -&gt; String -&gt; String -&gt; IO ()
</span><a href="#local-6989586621679557234"><span class="hs-identifier hs-var">shoveString</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557223"><span class="hs-identifier hs-var">n'</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557227"><span class="hs-identifier hs-var">cs</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557226"><span class="hs-identifier hs-var">rest</span></a></span><span>
</span><span id="line-696"></span><span>  </span><span class="hs-keyword">in</span><span>
</span><span id="line-697"></span><span>  </span><span class="annot"><span class="annottext">Int -&gt; String -&gt; String -&gt; IO ()
</span><a href="#local-6989586621679557234"><span class="hs-identifier hs-var">shoveString</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679557235"><span class="hs-identifier hs-var">s</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557240"><span class="hs-identifier hs-var">add_nl</span></a></span><span> </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;\n&quot;</span></span><span> </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;&quot;</span></span><span class="hs-special">)</span><span>
</span><span id="line-698"></span><span>
</span><span id="line-699"></span><span class="hs-comment">-- -----------------------------------------------------------------------------</span><span>
</span><span id="line-700"></span><span class="hs-comment">-- commitBuffer handle buf sz count flush release</span><span>
</span><span id="line-701"></span><span class="hs-comment">--</span><span>
</span><span id="line-702"></span><span class="hs-comment">-- Write the contents of the buffer 'buf' ('sz' bytes long, containing</span><span>
</span><span id="line-703"></span><span class="hs-comment">-- 'count' bytes of data) to handle (handle must be block or line buffered).</span><span>
</span><span id="line-704"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#commitBuffer"><span class="hs-identifier hs-type">commitBuffer</span></a></span><span>
</span><span id="line-705"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>                       </span><span class="hs-comment">-- handle to commit to</span><span>
</span><span id="line-706"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawCharBuffer"><span class="hs-identifier hs-type">RawCharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>         </span><span class="hs-comment">-- address and size (in bytes) of buffer</span><span>
</span><span id="line-707"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>                          </span><span class="hs-comment">-- number of bytes of data in buffer</span><span>
</span><span id="line-708"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>                         </span><span class="hs-comment">-- True &lt;=&gt; flush the handle afterward</span><span>
</span><span id="line-709"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>                         </span><span class="hs-comment">-- release the buffer?</span><span>
</span><span id="line-710"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-711"></span><span>
</span><span id="line-712"></span><span id="commitBuffer"><span class="annot"><span class="annottext">commitBuffer :: Handle -&gt; RawCharBuffer -&gt; Int -&gt; Int -&gt; Bool -&gt; Bool -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#commitBuffer"><span class="hs-identifier hs-var hs-var">commitBuffer</span></a></span></span><span> </span><span id="local-6989586621679557222"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557222"><span class="hs-identifier hs-var">hdl</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557221"><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557221"><span class="hs-identifier hs-var">raw</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557220"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557220"><span class="hs-identifier hs-var">sz</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557219"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557219"><span class="hs-identifier hs-var">count</span></a></span></span><span> </span><span id="local-6989586621679557218"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557218"><span class="hs-identifier hs-var">flush</span></a></span></span><span> </span><span id="local-6989586621679557217"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557217"><span class="hs-identifier hs-var">release</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-713"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; Handle -&gt; (Handle__ -&gt; IO ()) -&gt; IO ()
forall a. String -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantWritableHandle"><span class="hs-identifier hs-var">wantWritableHandle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;commitBuffer&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557222"><span class="hs-identifier hs-var">hdl</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO ()) -&gt; IO ()) -&gt; (Handle__ -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679557216"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679557216"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557179"><span id="local-6989586621679557180"><span id="local-6989586621679557181"><span id="local-6989586621679557182"><span id="local-6989586621679557183"><span id="local-6989586621679557184"><span id="local-6989586621679557185"><span id="local-6989586621679557186"><span id="local-6989586621679557187"><span id="local-6989586621679557188"><span id="local-6989586621679557189"><span id="local-6989586621679557190"><span id="local-6989586621679557191"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679557179"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-714"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;commitBuffer: sz=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557220"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;, count=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557219"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-715"></span><span>            </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;, flush=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557218"><span class="hs-identifier hs-var">flush</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;, release=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557217"><span class="hs-identifier hs-var">release</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;, handle=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557222"><span class="hs-identifier hs-var">hdl</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-716"></span><span>
</span><span id="line-717"></span><span>      </span><span class="hs-comment">-- Offset taken from handle</span><span>
</span><span id="line-718"></span><span>      </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#writeCharBuffer"><span class="hs-identifier hs-var">writeCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557216"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer :: forall e.
RawBuffer e
-&gt; BufferState -&gt; Int -&gt; Word64 -&gt; Int -&gt; Int -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: RawCharBuffer
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557221"><span class="hs-identifier hs-var">raw</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufState :: BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var">bufState</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufOffset :: Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Word64
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span>
</span><span id="line-719"></span><span>                                 </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557219"><span class="hs-identifier hs-var">count</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557220"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-720"></span><span>
</span><span id="line-721"></span><span>      </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557218"><span class="hs-identifier hs-var">flush</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushByteWriteBuffer"><span class="hs-identifier hs-var">flushByteWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557216"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-722"></span><span>
</span><span id="line-723"></span><span>      </span><span class="hs-comment">-- release the buffer if necessary</span><span>
</span><span id="line-724"></span><span>      </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557217"><span class="hs-identifier hs-var">release</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-725"></span><span>          </span><span class="hs-comment">-- find size of current buffer</span><span>
</span><span id="line-726"></span><span>          </span><span id="local-6989586621679557178"><span class="annot"><span class="annottext">old_buf :: Buffer Char
</span><a href="#local-6989586621679557178"><span class="hs-identifier hs-var">old_buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557177"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557177"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557186"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-727"></span><span>          </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557220"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557177"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-728"></span><span>               </span><span id="local-6989586621679557176"><span class="annot"><span class="annottext">BufferList Char
</span><a href="#local-6989586621679557176"><span class="hs-identifier hs-var">spare_bufs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (BufferList Char) -&gt; IO (BufferList Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (BufferList Char)
</span><a href="#local-6989586621679557185"><span class="hs-identifier hs-var">haBuffers</span></a></span><span>
</span><span id="line-729"></span><span>               </span><span class="annot"><span class="annottext">IORef (BufferList Char) -&gt; BufferList Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (BufferList Char)
</span><a href="#local-6989586621679557185"><span class="hs-identifier hs-var">haBuffers</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RawCharBuffer -&gt; BufferList Char -&gt; BufferList Char
forall e. RawBuffer e -&gt; BufferList e -&gt; BufferList e
</span><a href="GHC.IO.Handle.Types.html#BufferListCons"><span class="hs-identifier hs-var">BufferListCons</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557221"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">BufferList Char
</span><a href="#local-6989586621679557176"><span class="hs-identifier hs-var">spare_bufs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-730"></span><span>
</span><span id="line-731"></span><span>      </span><span class="hs-comment">-- bb &lt;- readIORef haByteBuffer</span><span>
</span><span id="line-732"></span><span>      </span><span class="hs-comment">-- debugIO (&quot;commitBuffer: buffer=&quot; ++ summaryBuffer bb ++ &quot;, handle=&quot; ++ show hdl)</span><span>
</span><span id="line-733"></span><span>      </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-734"></span><span>
</span><span id="line-735"></span><span class="hs-comment">-- backwards compatibility; the text package uses this</span><span>
</span><span id="line-736"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#commitBuffer%27"><span class="hs-identifier hs-type">commitBuffer'</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawCharBuffer"><span class="hs-identifier hs-type">RawCharBuffer</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span>
</span><span id="line-737"></span><span>              </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#CharBuffer"><span class="hs-identifier hs-type">CharBuffer</span></a></span><span>
</span><span id="line-738"></span><span id="commitBuffer%27"><span class="annot"><span class="annottext">commitBuffer' :: RawCharBuffer
-&gt; Int -&gt; Int -&gt; Bool -&gt; Bool -&gt; Handle__ -&gt; IO (Buffer Char)
</span><a href="GHC.IO.Handle.Text.html#commitBuffer%27"><span class="hs-identifier hs-var hs-var">commitBuffer'</span></a></span></span><span> </span><span id="local-6989586621679557175"><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557175"><span class="hs-identifier hs-var">raw</span></a></span></span><span> </span><span id="local-6989586621679557174"><span class="annot"><span class="annottext">sz :: Int
</span><a href="#local-6989586621679557174"><span class="hs-identifier hs-var">sz</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679557173"><span class="annot"><span class="annottext">count :: Int
</span><a href="#local-6989586621679557173"><span class="hs-identifier hs-var">count</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#I%23"><span class="hs-identifier hs-type">I#</span></a></span><span> </span><span class="annot"><span class="annottext">Int#
</span><span class="hs-identifier">_</span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621679557172"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557172"><span class="hs-identifier hs-var">flush</span></a></span></span><span> </span><span id="local-6989586621679557171"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557171"><span class="hs-identifier hs-var">release</span></a></span></span><span> </span><span id="local-6989586621679557170"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679557170"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557138"><span id="local-6989586621679557139"><span id="local-6989586621679557140"><span id="local-6989586621679557141"><span id="local-6989586621679557142"><span id="local-6989586621679557143"><span id="local-6989586621679557144"><span id="local-6989586621679557145"><span id="local-6989586621679557146"><span id="local-6989586621679557147"><span id="local-6989586621679557148"><span id="local-6989586621679557149"><span id="local-6989586621679557150"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679557138"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span>
</span><span id="line-739"></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-740"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;commitBuffer: sz=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557174"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;, count=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557173"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-741"></span><span>            </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;, flush=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557172"><span class="hs-identifier hs-var">flush</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;, release=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557171"><span class="hs-identifier hs-var">release</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-742"></span><span>
</span><span id="line-743"></span><span>      </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679557136"><span class="annot"><span class="annottext">this_buf :: Buffer Char
</span><a href="#local-6989586621679557136"><span class="hs-identifier hs-var hs-var">this_buf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer :: forall e.
RawBuffer e
-&gt; BufferState -&gt; Int -&gt; Word64 -&gt; Int -&gt; Int -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: RawCharBuffer
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557175"><span class="hs-identifier hs-var">raw</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufState :: BufferState
</span><a href="GHC.IO.Buffer.html#bufState"><span class="hs-identifier hs-var">bufState</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">BufferState
</span><a href="GHC.IO.Buffer.html#WriteBuffer"><span class="hs-identifier hs-var">WriteBuffer</span></a></span><span class="hs-special">,</span><span>
</span><span id="line-744"></span><span>                             </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557173"><span class="hs-identifier hs-var">count</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557174"><span class="hs-identifier hs-var">sz</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufOffset :: Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Word64
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-745"></span><span>
</span><span id="line-746"></span><span>      </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Char -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#writeCharBuffer"><span class="hs-identifier hs-var">writeCharBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557170"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557136"><span class="hs-identifier hs-var">this_buf</span></a></span><span>
</span><span id="line-747"></span><span>
</span><span id="line-748"></span><span>      </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557172"><span class="hs-identifier hs-var">flush</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushByteWriteBuffer"><span class="hs-identifier hs-var">flushByteWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557170"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-749"></span><span>
</span><span id="line-750"></span><span>      </span><span class="hs-comment">-- release the buffer if necessary</span><span>
</span><span id="line-751"></span><span>      </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557171"><span class="hs-identifier hs-var">release</span></a></span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-752"></span><span>          </span><span class="hs-comment">-- find size of current buffer</span><span>
</span><span id="line-753"></span><span>          </span><span id="local-6989586621679557135"><span class="annot"><span class="annottext">old_buf :: Buffer Char
</span><a href="#local-6989586621679557135"><span class="hs-identifier hs-var">old_buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557134"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557134"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char) -&gt; IO (Buffer Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Char)
</span><a href="#local-6989586621679557145"><span class="hs-identifier hs-var">haCharBuffer</span></a></span><span>
</span><span id="line-754"></span><span>          </span><span class="annot"><span class="annottext">Bool -&gt; IO () -&gt; IO ()
forall (f :: * -&gt; *). Applicative f =&gt; Bool -&gt; f () -&gt; f ()
</span><a href="GHC.Base.html#when"><span class="hs-identifier hs-var">when</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557174"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557134"><span class="hs-identifier hs-var">size</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">(IO () -&gt; IO ()) -&gt; IO () -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-755"></span><span>               </span><span id="local-6989586621679557133"><span class="annot"><span class="annottext">BufferList Char
</span><a href="#local-6989586621679557133"><span class="hs-identifier hs-var">spare_bufs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (BufferList Char) -&gt; IO (BufferList Char)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (BufferList Char)
</span><a href="#local-6989586621679557144"><span class="hs-identifier hs-var">haBuffers</span></a></span><span>
</span><span id="line-756"></span><span>               </span><span class="annot"><span class="annottext">IORef (BufferList Char) -&gt; BufferList Char -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (BufferList Char)
</span><a href="#local-6989586621679557144"><span class="hs-identifier hs-var">haBuffers</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RawCharBuffer -&gt; BufferList Char -&gt; BufferList Char
forall e. RawBuffer e -&gt; BufferList e -&gt; BufferList e
</span><a href="GHC.IO.Handle.Types.html#BufferListCons"><span class="hs-identifier hs-var">BufferListCons</span></a></span><span> </span><span class="annot"><span class="annottext">RawCharBuffer
</span><a href="#local-6989586621679557175"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">BufferList Char
</span><a href="#local-6989586621679557133"><span class="hs-identifier hs-var">spare_bufs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-757"></span><span>
</span><span id="line-758"></span><span>      </span><span class="annot"><span class="annottext">Buffer Char -&gt; IO (Buffer Char)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Char
</span><a href="#local-6989586621679557136"><span class="hs-identifier hs-var">this_buf</span></a></span><span>
</span><span id="line-759"></span><span>
</span><span id="line-760"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-761"></span><span class="hs-comment">-- Reading/writing sequences of bytes.</span><span>
</span><span id="line-762"></span><span>
</span><span id="line-763"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-764"></span><span class="hs-comment">-- hPutBuf</span><span>
</span><span id="line-765"></span><span>
</span><span id="line-766"></span><span class="hs-comment">-- | 'hPutBuf' @hdl buf count@ writes @count@ 8-bit bytes from the</span><span>
</span><span id="line-767"></span><span class="hs-comment">-- buffer @buf@ to the handle @hdl@.  It returns ().</span><span>
</span><span id="line-768"></span><span class="hs-comment">--</span><span>
</span><span id="line-769"></span><span class="hs-comment">-- 'hPutBuf' ignores any text encoding that applies to the 'Handle',</span><span>
</span><span id="line-770"></span><span class="hs-comment">-- writing the bytes directly to the underlying file or device.</span><span>
</span><span id="line-771"></span><span class="hs-comment">--</span><span>
</span><span id="line-772"></span><span class="hs-comment">-- 'hPutBuf' ignores the prevailing 'System.IO.TextEncoding' and</span><span>
</span><span id="line-773"></span><span class="hs-comment">-- 'NewlineMode' on the 'Handle', and writes bytes directly.</span><span>
</span><span id="line-774"></span><span class="hs-comment">--</span><span>
</span><span id="line-775"></span><span class="hs-comment">-- This operation may fail with:</span><span>
</span><span id="line-776"></span><span class="hs-comment">--</span><span>
</span><span id="line-777"></span><span class="hs-comment">--  * 'ResourceVanished' if the handle is a pipe or socket, and the</span><span>
</span><span id="line-778"></span><span class="hs-comment">--    reading end is closed.  (If this is a POSIX system, and the program</span><span>
</span><span id="line-779"></span><span class="hs-comment">--    has not asked to ignore SIGPIPE, then a SIGPIPE may be delivered</span><span>
</span><span id="line-780"></span><span class="hs-comment">--    instead, whose default action is to terminate the program).</span><span>
</span><span id="line-781"></span><span>
</span><span id="line-782"></span><span id="local-6989586621679557979"><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutBuf"><span class="hs-identifier hs-type">hPutBuf</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>                       </span><span class="hs-comment">-- handle to write to</span><span>
</span><span id="line-783"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679557979"><span class="hs-identifier hs-type">a</span></a></span><span>                        </span><span class="hs-comment">-- address of buffer</span><span>
</span><span id="line-784"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>                          </span><span class="hs-comment">-- number of bytes of data in buffer</span><span>
</span><span id="line-785"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-786"></span><span id="hPutBuf"><span class="annot"><span class="annottext">hPutBuf :: forall a. Handle -&gt; Ptr a -&gt; Int -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#hPutBuf"><span class="hs-identifier hs-var hs-var">hPutBuf</span></a></span></span><span> </span><span id="local-6989586621679557130"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557130"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679557129"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679557129"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679557128"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557128"><span class="hs-identifier hs-var">count</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; Ptr a -&gt; Int -&gt; Bool -&gt; IO Int
forall a. Handle -&gt; Ptr a -&gt; Int -&gt; Bool -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#hPutBuf%27"><span class="hs-identifier hs-var">hPutBuf'</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557130"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679557129"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557128"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span>
</span><span id="line-787"></span><span>                         </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-788"></span><span>
</span><span id="line-789"></span><span id="local-6989586621679557976"><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutBufNonBlocking"><span class="hs-identifier hs-type">hPutBufNonBlocking</span></a></span><span>
</span><span id="line-790"></span><span>        </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>                       </span><span class="hs-comment">-- handle to write to</span><span>
</span><span id="line-791"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679557976"><span class="hs-identifier hs-type">a</span></a></span><span>                        </span><span class="hs-comment">-- address of buffer</span><span>
</span><span id="line-792"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>                          </span><span class="hs-comment">-- number of bytes of data in buffer</span><span>
</span><span id="line-793"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span></span><span>                       </span><span class="hs-comment">-- returns: number of bytes written</span><span>
</span><span id="line-794"></span><span id="hPutBufNonBlocking"><span class="annot"><span class="annottext">hPutBufNonBlocking :: forall a. Handle -&gt; Ptr a -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#hPutBufNonBlocking"><span class="hs-identifier hs-var hs-var">hPutBufNonBlocking</span></a></span></span><span> </span><span id="local-6989586621679557126"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557126"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span id="local-6989586621679557125"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679557125"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679557124"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557124"><span class="hs-identifier hs-var">count</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; Ptr a -&gt; Int -&gt; Bool -&gt; IO Int
forall a. Handle -&gt; Ptr a -&gt; Int -&gt; Bool -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#hPutBuf%27"><span class="hs-identifier hs-var">hPutBuf'</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557126"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679557125"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557124"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#False"><span class="hs-identifier hs-var">False</span></a></span><span>
</span><span id="line-795"></span><span>
</span><span id="line-796"></span><span id="local-6989586621679557977"><span class="annot"><a href="GHC.IO.Handle.Text.html#hPutBuf%27"><span class="hs-identifier hs-type">hPutBuf'</span></a></span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span>                       </span><span class="hs-comment">-- handle to write to</span><span>
</span><span id="line-797"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679557977"><span class="hs-identifier hs-type">a</span></a></span><span>                        </span><span class="hs-comment">-- address of buffer</span><span>
</span><span id="line-798"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>                          </span><span class="hs-comment">-- number of bytes of data in buffer</span><span>
</span><span id="line-799"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span>                         </span><span class="hs-comment">-- allow blocking?</span><span>
</span><span id="line-800"></span><span>        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span></span><span>
</span><span id="line-801"></span><span id="hPutBuf%27"><span class="annot"><span class="annottext">hPutBuf' :: forall a. Handle -&gt; Ptr a -&gt; Int -&gt; Bool -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#hPutBuf%27"><span class="hs-identifier hs-var hs-var">hPutBuf'</span></a></span></span><span> </span><span id="local-6989586621679557117"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557117"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span id="local-6989586621679557116"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679557116"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679557115"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557115"><span class="hs-identifier hs-var">count</span></a></span></span><span> </span><span id="local-6989586621679557114"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557114"><span class="hs-identifier hs-var">can_block</span></a></span></span><span>
</span><span id="line-802"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557115"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-803"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557115"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span>  </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; Int -&gt; IO Int
forall a. Handle -&gt; String -&gt; Int -&gt; IO a
</span><a href="GHC.IO.Handle.Text.html#illegalBufferSize"><span class="hs-identifier hs-var">illegalBufferSize</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557117"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hPutBuf&quot;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557115"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-804"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-805"></span><span>    </span><span class="annot"><span class="annottext">String -&gt; Handle -&gt; (Handle__ -&gt; IO Int) -&gt; IO Int
forall a. String -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantWritableHandle"><span class="hs-identifier hs-var">wantWritableHandle</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hPutBuf&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679557117"><span class="hs-identifier hs-var">handle</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO Int) -&gt; IO Int) -&gt; (Handle__ -&gt; IO Int) -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-806"></span><span>      </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679557112"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679557112"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557089"><span id="local-6989586621679557090"><span id="local-6989586621679557091"><span id="local-6989586621679557092"><span id="local-6989586621679557093"><span id="local-6989586621679557094"><span id="local-6989586621679557095"><span id="local-6989586621679557096"><span id="local-6989586621679557097"><span id="local-6989586621679557098"><span id="local-6989586621679557099"><span id="local-6989586621679557100"><span id="local-6989586621679557101"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679557089"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-807"></span><span>          </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hPutBuf count=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557115"><span class="hs-identifier hs-var">count</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-808"></span><span>
</span><span id="line-809"></span><span>          </span><span id="local-6989586621679557088"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557088"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Ptr Word8 -&gt; Int -&gt; Bool -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufWrite"><span class="hs-identifier hs-var">bufWrite</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557112"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679557116"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557115"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557114"><span class="hs-identifier hs-var">can_block</span></a></span><span>
</span><span id="line-810"></span><span>
</span><span id="line-811"></span><span>          </span><span class="hs-comment">-- we must flush if this Handle is set to NoBuffering.  If</span><span>
</span><span id="line-812"></span><span>          </span><span class="hs-comment">-- it is set to LineBuffering, be conservative and flush</span><span>
</span><span id="line-813"></span><span>          </span><span class="hs-comment">-- anyway (we didn't check for newlines in the data).</span><span>
</span><span id="line-814"></span><span>          </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679557098"><span class="hs-identifier hs-var">haBufferMode</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-815"></span><span>             </span><span class="annot"><a href="GHC.IO.Handle.Types.html#BlockBuffering"><span class="hs-identifier hs-type">BlockBuffering</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe Int
</span><span class="hs-identifier">_</span></span><span>      </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-816"></span><span>             </span><span id="local-6989586621679557085"><span class="annot"><span class="annottext">BufferMode
</span><a href="#local-6989586621679557085"><span class="hs-identifier hs-var">_line_or_no_buffering</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushWriteBuffer"><span class="hs-identifier hs-var">flushWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557112"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-817"></span><span>          </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557088"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-818"></span><span>
</span><span id="line-819"></span><span class="hs-comment">-- TODO: Possible optimisation:</span><span>
</span><span id="line-820"></span><span class="hs-comment">--       If we know that `w + count &gt; size`, we should write both the</span><span>
</span><span id="line-821"></span><span class="hs-comment">--       handle buffer and the `ptr` in a single `writev()` syscall.</span><span>
</span><span id="line-822"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#bufWrite"><span class="hs-identifier hs-type">bufWrite</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Bool"><span class="hs-identifier hs-type">Bool</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-823"></span><span id="bufWrite"><span class="annot"><span class="annottext">bufWrite :: Handle__ -&gt; Ptr Word8 -&gt; Int -&gt; Bool -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufWrite"><span class="hs-identifier hs-var hs-var">bufWrite</span></a></span></span><span> </span><span id="local-6989586621679557083"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679557083"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557054"><span id="local-6989586621679557055"><span id="local-6989586621679557056"><span id="local-6989586621679557057"><span id="local-6989586621679557058"><span id="local-6989586621679557059"><span id="local-6989586621679557060"><span id="local-6989586621679557061"><span id="local-6989586621679557062"><span id="local-6989586621679557063"><span id="local-6989586621679557064"><span id="local-6989586621679557065"><span id="local-6989586621679557066"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679557054"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span id="local-6989586621679557053"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679557053"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679557052"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557052"><span class="hs-identifier hs-var">count</span></a></span></span><span> </span><span id="local-6989586621679557051"><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557051"><span class="hs-identifier hs-var">can_block</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-824"></span><span>  </span><span class="hs-comment">-- Get buffer to determine size and free space in buffer</span><span>
</span><span id="line-825"></span><span>  </span><span id="local-6989586621679557050"><span class="annot"><span class="annottext">old_buf :: Buffer Word8
</span><a href="#local-6989586621679557050"><span class="hs-identifier hs-var">old_buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557049"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557049"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679557048"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557048"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-826"></span><span>      </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679557064"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-827"></span><span>
</span><span id="line-828"></span><span>  </span><span class="hs-comment">-- There's no need to buffer if the incoming data is larger than</span><span>
</span><span id="line-829"></span><span>  </span><span class="hs-comment">-- the handle buffer (`count &gt;= size`).</span><span>
</span><span id="line-830"></span><span>  </span><span class="hs-comment">-- Check if we can try to buffer the given chunk of data.</span><span>
</span><span id="line-831"></span><span>  </span><span id="local-6989586621679557047"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557047"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557052"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557048"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%26%26"><span class="hs-operator hs-var">&amp;&amp;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557052"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557048"><span class="hs-identifier hs-var">size</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557049"><span class="hs-identifier hs-var">w</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-832"></span><span>        </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufferChunk"><span class="hs-identifier hs-var">bufferChunk</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557083"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557050"><span class="hs-identifier hs-var">old_buf</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679557053"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557052"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-833"></span><span>        </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-834"></span><span>          </span><span class="hs-comment">-- The given data does not fit into the buffer.</span><span>
</span><span id="line-835"></span><span>          </span><span class="hs-comment">-- Either because it's too large for the buffer</span><span>
</span><span id="line-836"></span><span>          </span><span class="hs-comment">-- or the buffer is too full. Either way we need</span><span>
</span><span id="line-837"></span><span>          </span><span class="hs-comment">-- to flush the buffered data first.</span><span>
</span><span id="line-838"></span><span>          </span><span id="local-6989586621679557044"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557044"><span class="hs-identifier hs-var">flushed_buf</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.Handle.Text.html#flushByteWriteBufferGiven"><span class="hs-identifier hs-var">flushByteWriteBufferGiven</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557083"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557050"><span class="hs-identifier hs-var">old_buf</span></a></span><span>
</span><span id="line-839"></span><span>          </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557052"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557048"><span class="hs-identifier hs-var">size</span></a></span><span>
</span><span id="line-840"></span><span>              </span><span class="hs-comment">-- The data is small enough to be buffered.</span><span>
</span><span id="line-841"></span><span>              </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufferChunk"><span class="hs-identifier hs-var">bufferChunk</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557083"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557044"><span class="hs-identifier hs-var">flushed_buf</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679557053"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557052"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-842"></span><span>              </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-843"></span><span>                </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679557042"><span class="annot"><span class="annottext">offset :: Word64
</span><a href="#local-6989586621679557042"><span class="hs-identifier hs-var hs-var">offset</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Word64
forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var hs-var">bufOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557044"><span class="hs-identifier hs-var">flushed_buf</span></a></span><span>
</span><span id="line-844"></span><span>                </span><span class="hs-glyph">!</span><span id="local-6989586621679557041"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557041"><span class="hs-identifier hs-var">bytes</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="#local-6989586621679557051"><span class="hs-identifier hs-var">can_block</span></a></span><span>
</span><span id="line-845"></span><span>                            </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#writeChunk"><span class="hs-identifier hs-var">writeChunk</span></a></span><span>         </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557083"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679557053"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679557042"><span class="hs-identifier hs-var">offset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557052"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-846"></span><span>                            </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#writeChunkNonBlocking"><span class="hs-identifier hs-var">writeChunkNonBlocking</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557083"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679557053"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679557042"><span class="hs-identifier hs-var">offset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557052"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-847"></span><span>                </span><span class="hs-comment">-- Update buffer with actual bytes written.</span><span>
</span><span id="line-848"></span><span>                </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679557064"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">(Buffer Word8 -&gt; IO ()) -&gt; Buffer Word8 -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Word8 -&gt; Buffer Word8
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAddOffset"><span class="hs-identifier hs-var">bufferAddOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557041"><span class="hs-identifier hs-var">bytes</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557044"><span class="hs-identifier hs-var">flushed_buf</span></a></span><span>
</span><span id="line-849"></span><span>                </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557041"><span class="hs-identifier hs-var">bytes</span></a></span><span>
</span><span id="line-850"></span><span>  </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hPutBuf: done&quot;</span></span><span>
</span><span id="line-851"></span><span>  </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679557047"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-852"></span><span>
</span><span id="line-853"></span><span class="hs-comment">-- Flush the given buffer via the handle, return the flushed buffer</span><span>
</span><span id="line-854"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#flushByteWriteBufferGiven"><span class="hs-identifier hs-type">flushByteWriteBufferGiven</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-855"></span><span id="flushByteWriteBufferGiven"><span class="annot"><span class="annottext">flushByteWriteBufferGiven :: Handle__ -&gt; Buffer Word8 -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.Handle.Text.html#flushByteWriteBufferGiven"><span class="hs-identifier hs-var hs-var">flushByteWriteBufferGiven</span></a></span></span><span> </span><span id="local-6989586621679557036"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679557036"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679557013"><span id="local-6989586621679557014"><span id="local-6989586621679557015"><span id="local-6989586621679557016"><span id="local-6989586621679557017"><span id="local-6989586621679557018"><span id="local-6989586621679557019"><span id="local-6989586621679557020"><span id="local-6989586621679557021"><span id="local-6989586621679557022"><span id="local-6989586621679557023"><span id="local-6989586621679557024"><span id="local-6989586621679557025"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679557013"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span id="local-6989586621679557012"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557012"><span class="hs-identifier hs-var">bbuf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-856"></span><span>  </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#not"><span class="hs-identifier hs-var">not</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557012"><span class="hs-identifier hs-var">bbuf</span></a></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-857"></span><span>    </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-858"></span><span>      </span><span id="local-6989586621679557011"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557011"><span class="hs-identifier hs-var">bbuf'</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Buffer Word8 -&gt; IO (Buffer Word8)
forall dev.
BufferedIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#flushWriteBuffer"><span class="hs-identifier hs-var">Buffered.flushWriteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679557025"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557012"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-859"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;flushByteWriteBufferGiven: bbuf=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557011"><span class="hs-identifier hs-var">bbuf'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-860"></span><span>      </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679557023"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557011"><span class="hs-identifier hs-var">bbuf'</span></a></span><span>
</span><span id="line-861"></span><span>      </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; IO (Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557011"><span class="hs-identifier hs-var">bbuf'</span></a></span><span>
</span><span id="line-862"></span><span>    </span><span class="hs-keyword">else</span><span>
</span><span id="line-863"></span><span>      </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; IO (Buffer Word8)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679557012"><span class="hs-identifier hs-var">bbuf</span></a></span><span>
</span><span id="line-864"></span><span>
</span><span id="line-865"></span><span class="hs-comment">-- Fill buffer and return bytes buffered/written.</span><span>
</span><span id="line-866"></span><span class="hs-comment">-- Flushes buffer if it's full after adding the data.</span><span>
</span><span id="line-867"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#bufferChunk"><span class="hs-identifier hs-type">bufferChunk</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-868"></span><span id="bufferChunk"><span class="annot"><span class="annottext">bufferChunk :: Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufferChunk"><span class="hs-identifier hs-var hs-var">bufferChunk</span></a></span></span><span> </span><span id="local-6989586621679557009"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679557009"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679556984"><span id="local-6989586621679556985"><span id="local-6989586621679556986"><span id="local-6989586621679556987"><span id="local-6989586621679556988"><span id="local-6989586621679556989"><span id="local-6989586621679556990"><span id="local-6989586621679556991"><span id="local-6989586621679556992"><span id="local-6989586621679556993"><span id="local-6989586621679556994"><span id="local-6989586621679556995"><span id="local-6989586621679556996"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679556984"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span id="local-6989586621679556983"><span class="annot"><span class="annottext">old_buf :: Buffer Word8
</span><a href="#local-6989586621679556983"><span class="hs-identifier hs-var">old_buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556982"><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679556982"><span class="hs-identifier hs-var">raw</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556981"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556981"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556980"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556980"><span class="hs-identifier hs-var">size</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span id="local-6989586621679556979"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556979"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679556978"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556978"><span class="hs-identifier hs-var">count</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-869"></span><span>    </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hPutBuf: copying to buffer, w=&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556981"><span class="hs-identifier hs-var">w</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-870"></span><span>    </span><span class="annot"><span class="annottext">RawBuffer Word8 -&gt; Int -&gt; Ptr Word8 -&gt; Int -&gt; IO ()
forall e. RawBuffer e -&gt; Int -&gt; Ptr e -&gt; Int -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#copyToRawBuffer"><span class="hs-identifier hs-var">copyToRawBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679556982"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556981"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556979"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556978"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-871"></span><span>    </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679556975"><span class="annot"><span class="annottext">copied_buf :: Buffer Word8
</span><a href="#local-6989586621679556975"><span class="hs-identifier hs-var hs-var">copied_buf</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556983"><span class="hs-identifier hs-var">old_buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556981"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556978"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-872"></span><span>    </span><span class="hs-comment">-- If the write filled the buffer completely, we need to flush,</span><span>
</span><span id="line-873"></span><span>    </span><span class="hs-comment">-- to maintain the &quot;INVARIANTS on Buffers&quot; from</span><span>
</span><span id="line-874"></span><span>    </span><span class="hs-comment">-- GHC.IO.Buffer.checkBuffer: &quot;a write buffer is never full&quot;.</span><span>
</span><span id="line-875"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isFullBuffer"><span class="hs-identifier hs-var">isFullBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556975"><span class="hs-identifier hs-var">copied_buf</span></a></span><span>
</span><span id="line-876"></span><span>      </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-877"></span><span>        </span><span class="hs-comment">-- TODO: we should do a non-blocking flush here</span><span>
</span><span id="line-878"></span><span>        </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hPutBuf: flushing full buffer after writing&quot;</span></span><span>
</span><span id="line-879"></span><span>        </span><span class="annot"><span class="annottext">Buffer Word8
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; IO (Buffer Word8)
</span><a href="GHC.IO.Handle.Text.html#flushByteWriteBufferGiven"><span class="hs-identifier hs-var">flushByteWriteBufferGiven</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679557009"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556975"><span class="hs-identifier hs-var">copied_buf</span></a></span><span>
</span><span id="line-880"></span><span>        </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-881"></span><span>      </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-882"></span><span>        </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556994"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556975"><span class="hs-identifier hs-var">copied_buf</span></a></span><span>
</span><span id="line-883"></span><span>    </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556978"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-884"></span><span>
</span><span id="line-885"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#writeChunk"><span class="hs-identifier hs-type">writeChunk</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Word.html#Word64"><span class="hs-identifier hs-type">Word64</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-886"></span><span id="writeChunk"><span class="annot"><span class="annottext">writeChunk :: Handle__ -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#writeChunk"><span class="hs-identifier hs-var hs-var">writeChunk</span></a></span></span><span> </span><span id="local-6989586621679556973"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679556973"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679556953"><span id="local-6989586621679556954"><span id="local-6989586621679556955"><span id="local-6989586621679556956"><span id="local-6989586621679556957"><span id="local-6989586621679556958"><span id="local-6989586621679556959"><span id="local-6989586621679556960"><span id="local-6989586621679556961"><span id="local-6989586621679556962"><span id="local-6989586621679556963"><span id="local-6989586621679556964"><span id="local-6989586621679556965"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679556953"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span id="local-6989586621679556952"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556952"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679556951"><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556951"><span class="hs-identifier hs-var">offset</span></a></span></span><span> </span><span id="local-6989586621679556950"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556950"><span class="hs-identifier hs-var">bytes</span></a></span></span><span>
</span><span id="line-887"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO ()
forall a. RawIO a =&gt; a -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO ()
</span><a href="GHC.IO.Device.html#write"><span class="hs-identifier hs-var">RawIO.write</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679556965"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556952"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556951"><span class="hs-identifier hs-var">offset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556950"><span class="hs-identifier hs-var">bytes</span></a></span><span>
</span><span id="line-888"></span><span>       </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556950"><span class="hs-identifier hs-var">bytes</span></a></span><span>
</span><span id="line-889"></span><span>
</span><span id="line-890"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#writeChunkNonBlocking"><span class="hs-identifier hs-type">writeChunkNonBlocking</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Word.html#Word64"><span class="hs-identifier hs-type">Word64</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-891"></span><span id="writeChunkNonBlocking"><span class="annot"><span class="annottext">writeChunkNonBlocking :: Handle__ -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#writeChunkNonBlocking"><span class="hs-identifier hs-var hs-var">writeChunkNonBlocking</span></a></span></span><span> </span><span id="local-6989586621679556948"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679556948"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679556930"><span id="local-6989586621679556931"><span id="local-6989586621679556932"><span id="local-6989586621679556933"><span id="local-6989586621679556934"><span id="local-6989586621679556935"><span id="local-6989586621679556936"><span id="local-6989586621679556937"><span id="local-6989586621679556938"><span id="local-6989586621679556939"><span id="local-6989586621679556940"><span id="local-6989586621679556941"><span id="local-6989586621679556942"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679556930"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span id="local-6989586621679556929"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556929"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679556928"><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556928"><span class="hs-identifier hs-var">offset</span></a></span></span><span> </span><span id="local-6989586621679556927"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556927"><span class="hs-identifier hs-var">bytes</span></a></span></span><span>
</span><span id="line-892"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
forall a. RawIO a =&gt; a -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Device.html#writeNonBlocking"><span class="hs-identifier hs-var">RawIO.writeNonBlocking</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679556942"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556929"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556928"><span class="hs-identifier hs-var">offset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556927"><span class="hs-identifier hs-var">bytes</span></a></span><span>
</span><span id="line-893"></span><span>
</span><span id="line-894"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-895"></span><span class="hs-comment">-- hGetBuf</span><span>
</span><span id="line-896"></span><span>
</span><span id="line-897"></span><span class="hs-comment">-- | 'hGetBuf' @hdl buf count@ reads data from the handle @hdl@</span><span>
</span><span id="line-898"></span><span class="hs-comment">-- into the buffer @buf@ until either EOF is reached or</span><span>
</span><span id="line-899"></span><span class="hs-comment">-- @count@ 8-bit bytes have been read.</span><span>
</span><span id="line-900"></span><span class="hs-comment">-- It returns the number of bytes actually read.  This may be zero if</span><span>
</span><span id="line-901"></span><span class="hs-comment">-- EOF was reached before any data was read (or if @count@ is zero).</span><span>
</span><span id="line-902"></span><span class="hs-comment">--</span><span>
</span><span id="line-903"></span><span class="hs-comment">-- 'hGetBuf' never raises an EOF exception, instead it returns a value</span><span>
</span><span id="line-904"></span><span class="hs-comment">-- smaller than @count@.</span><span>
</span><span id="line-905"></span><span class="hs-comment">--</span><span>
</span><span id="line-906"></span><span class="hs-comment">-- If the handle is a pipe or socket, and the writing end</span><span>
</span><span id="line-907"></span><span class="hs-comment">-- is closed, 'hGetBuf' will behave as if EOF was reached.</span><span>
</span><span id="line-908"></span><span class="hs-comment">--</span><span>
</span><span id="line-909"></span><span class="hs-comment">-- 'hGetBuf' ignores the prevailing 'System.IO.TextEncoding' and 'NewlineMode'</span><span>
</span><span id="line-910"></span><span class="hs-comment">-- on the 'Handle', and reads bytes directly.</span><span>
</span><span id="line-911"></span><span>
</span><span id="line-912"></span><span id="local-6989586621679556925"><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetBuf"><span class="hs-identifier hs-type">hGetBuf</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679556925"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span></span><span>
</span><span id="line-913"></span><span id="hGetBuf"><span class="annot"><span class="annottext">hGetBuf :: forall a. Handle -&gt; Ptr a -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#hGetBuf"><span class="hs-identifier hs-var hs-var">hGetBuf</span></a></span></span><span> </span><span id="local-6989586621679556918"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679556918"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679556917"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679556917"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679556916"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556916"><span class="hs-identifier hs-var">count</span></a></span></span><span>
</span><span id="line-914"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556916"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-915"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556916"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span>  </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; Int -&gt; IO Int
forall a. Handle -&gt; String -&gt; Int -&gt; IO a
</span><a href="GHC.IO.Handle.Text.html#illegalBufferSize"><span class="hs-identifier hs-var">illegalBufferSize</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679556918"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetBuf&quot;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556916"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-916"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-917"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; Handle -&gt; (Handle__ -&gt; IO Int) -&gt; IO Int
forall a. String -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle_"><span class="hs-identifier hs-var">wantReadableHandle_</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetBuf&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679556918"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO Int) -&gt; IO Int) -&gt; (Handle__ -&gt; IO Int) -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679556915"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679556915"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679556889"><span id="local-6989586621679556890"><span id="local-6989586621679556891"><span id="local-6989586621679556892"><span id="local-6989586621679556893"><span id="local-6989586621679556894"><span id="local-6989586621679556895"><span id="local-6989586621679556896"><span id="local-6989586621679556897"><span id="local-6989586621679556898"><span id="local-6989586621679556899"><span id="local-6989586621679556900"><span id="local-6989586621679556901"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679556889"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-918"></span><span>          </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;:: hGetBuf - &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679556918"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; - &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556916"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-919"></span><span>          </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushCharReadBuffer"><span class="hs-identifier hs-var">flushCharReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556915"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-920"></span><span>          </span><span id="local-6989586621679556887"><span class="annot"><span class="annottext">buf :: Buffer Word8
</span><a href="#local-6989586621679556887"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556886"><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679556886"><span class="hs-identifier hs-var">raw</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556885"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556885"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556884"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556884"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556883"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556883"><span class="hs-identifier hs-var">sz</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-921"></span><span>            </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556899"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-922"></span><span>          </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetBuf: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556887"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-923"></span><span>          </span><span id="local-6989586621679556882"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556882"><span class="hs-identifier hs-var">res</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556887"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-924"></span><span>                    </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadEmpty"><span class="hs-identifier hs-var">bufReadEmpty</span></a></span><span>    </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556915"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556887"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679556917"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556916"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-925"></span><span>                    </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadNonEmpty"><span class="hs-identifier hs-var">bufReadNonEmpty</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556915"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556887"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679556917"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556916"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-926"></span><span>          </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;** hGetBuf done.&quot;</span></span><span>
</span><span id="line-927"></span><span>          </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556882"><span class="hs-identifier hs-var">res</span></a></span><span>
</span><span id="line-928"></span><span>
</span><span id="line-929"></span><span class="hs-comment">-- small reads go through the buffer, large reads are satisfied by</span><span>
</span><span id="line-930"></span><span class="hs-comment">-- taking data first from the buffer and then direct from the file</span><span>
</span><span id="line-931"></span><span class="hs-comment">-- descriptor.</span><span>
</span><span id="line-932"></span><span>
</span><span id="line-933"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#bufReadNonEmpty"><span class="hs-identifier hs-type">bufReadNonEmpty</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-934"></span><span id="bufReadNonEmpty"><span class="annot"><span class="annottext">bufReadNonEmpty :: Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadNonEmpty"><span class="hs-identifier hs-var hs-var">bufReadNonEmpty</span></a></span></span><span> </span><span id="local-6989586621679556879"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679556879"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679556844"><span id="local-6989586621679556845"><span id="local-6989586621679556846"><span id="local-6989586621679556847"><span id="local-6989586621679556848"><span id="local-6989586621679556849"><span id="local-6989586621679556850"><span id="local-6989586621679556851"><span id="local-6989586621679556852"><span id="local-6989586621679556853"><span id="local-6989586621679556854"><span id="local-6989586621679556855"><span id="local-6989586621679556856"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679556844"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span>
</span><span id="line-935"></span><span>                </span><span class="hs-comment">-- w for width, r for ... read ptr?</span><span>
</span><span id="line-936"></span><span>                </span><span id="local-6989586621679556843"><span class="annot"><span class="annottext">buf :: Buffer Word8
</span><a href="#local-6989586621679556843"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556842"><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679556842"><span class="hs-identifier hs-var">raw</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556841"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556841"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556840"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556840"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556839"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556839"><span class="hs-identifier hs-var">sz</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-937"></span><span>                </span><span id="local-6989586621679556838"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556838"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679556837"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556837"><span class="hs-identifier hs-var">so_far</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679556836"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556836"><span class="hs-identifier hs-var">count</span></a></span></span><span>
</span><span id="line-938"></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-939"></span><span>        </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;:: bufReadNonEmpty&quot;</span></span><span>
</span><span id="line-940"></span><span>        </span><span class="hs-comment">-- We use &lt; instead of &lt;= because for count == avail</span><span>
</span><span id="line-941"></span><span>        </span><span class="hs-comment">-- we need to reset bufL and bufR to zero.</span><span>
</span><span id="line-942"></span><span>        </span><span class="hs-comment">-- See also: INVARIANTS on Buffers</span><span>
</span><span id="line-943"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679556834"><span class="annot"><span class="annottext">avail :: Int
</span><a href="#local-6989586621679556834"><span class="hs-identifier hs-var hs-var">avail</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556841"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556840"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-944"></span><span>        </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556836"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556834"><span class="hs-identifier hs-var">avail</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-945"></span><span>           </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-946"></span><span>                </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; RawBuffer Word8 -&gt; Int -&gt; Int -&gt; IO ()
forall e. Ptr e -&gt; RawBuffer e -&gt; Int -&gt; Int -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#copyFromRawBuffer"><span class="hs-identifier hs-var">copyFromRawBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556838"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679556842"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556840"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556836"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-947"></span><span>                </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556854"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556843"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556840"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556836"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-948"></span><span>                </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556837"><span class="hs-identifier hs-var">so_far</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556836"><span class="hs-identifier hs-var">count</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-949"></span><span>           </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-950"></span><span>
</span><span id="line-951"></span><span>        </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; RawBuffer Word8 -&gt; Int -&gt; Int -&gt; IO ()
forall e. Ptr e -&gt; RawBuffer e -&gt; Int -&gt; Int -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#copyFromRawBuffer"><span class="hs-identifier hs-var">copyFromRawBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556838"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679556842"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556840"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556834"><span class="hs-identifier hs-var">avail</span></a></span><span>
</span><span id="line-952"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679556832"><span class="annot"><span class="annottext">buf' :: Buffer Word8
</span><a href="#local-6989586621679556832"><span class="hs-identifier hs-var hs-var">buf'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556843"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-953"></span><span>        </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556854"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556832"><span class="hs-identifier hs-var">buf'</span></a></span><span>
</span><span id="line-954"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679556830"><span class="annot"><span class="annottext">remaining :: Int
</span><a href="#local-6989586621679556830"><span class="hs-identifier hs-var hs-var">remaining</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556836"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556834"><span class="hs-identifier hs-var">avail</span></a></span><span>
</span><span id="line-955"></span><span>            </span><span id="local-6989586621679556828"><span class="annot"><span class="annottext">so_far' :: Int
</span><a href="#local-6989586621679556828"><span class="hs-identifier hs-var hs-var">so_far'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556837"><span class="hs-identifier hs-var">so_far</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556834"><span class="hs-identifier hs-var">avail</span></a></span><span>
</span><span id="line-956"></span><span>            </span><span id="local-6989586621679556827"><span class="annot"><span class="annottext">ptr' :: Ptr b
</span><a href="#local-6989586621679556827"><span class="hs-identifier hs-var hs-var">ptr'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556838"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr b
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556834"><span class="hs-identifier hs-var">avail</span></a></span><span>
</span><span id="line-957"></span><span>
</span><span id="line-958"></span><span>        </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;bufReadNonEmpty: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556832"><span class="hs-identifier hs-var">buf'</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; s:&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556828"><span class="hs-identifier hs-var">so_far'</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; r:&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556830"><span class="hs-identifier hs-var">remaining</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-959"></span><span>        </span><span id="local-6989586621679556825"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556825"><span class="hs-identifier hs-var">b</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556830"><span class="hs-identifier hs-var">remaining</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-960"></span><span>           </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556828"><span class="hs-identifier hs-var">so_far'</span></a></span><span>
</span><span id="line-961"></span><span>           </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadEmpty"><span class="hs-identifier hs-var">bufReadEmpty</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556879"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556832"><span class="hs-identifier hs-var">buf'</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
forall {b}. Ptr b
</span><a href="#local-6989586621679556827"><span class="hs-identifier hs-var">ptr'</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556828"><span class="hs-identifier hs-var">so_far'</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556830"><span class="hs-identifier hs-var">remaining</span></a></span><span>
</span><span id="line-962"></span><span>        </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;:: bufReadNonEmpty - done&quot;</span></span><span>
</span><span id="line-963"></span><span>        </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556825"><span class="hs-identifier hs-var">b</span></a></span><span>
</span><span id="line-964"></span><span>
</span><span id="line-965"></span><span class="hs-comment">-- We want to read more data, but the buffer is empty. (buffL == buffR == 0)</span><span>
</span><span id="line-966"></span><span class="hs-comment">-- See also Note [INVARIANTS on Buffers] in Buffer.hs</span><span>
</span><span id="line-967"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#bufReadEmpty"><span class="hs-identifier hs-type">bufReadEmpty</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-968"></span><span id="bufReadEmpty"><span class="annot"><span class="annottext">bufReadEmpty :: Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadEmpty"><span class="hs-identifier hs-var hs-var">bufReadEmpty</span></a></span></span><span> </span><span id="local-6989586621679556824"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679556824"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679556794"><span id="local-6989586621679556795"><span id="local-6989586621679556796"><span id="local-6989586621679556797"><span id="local-6989586621679556798"><span id="local-6989586621679556799"><span id="local-6989586621679556800"><span id="local-6989586621679556801"><span id="local-6989586621679556802"><span id="local-6989586621679556803"><span id="local-6989586621679556804"><span id="local-6989586621679556805"><span id="local-6989586621679556806"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679556794"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span>
</span><span id="line-969"></span><span>             </span><span id="local-6989586621679556793"><span class="annot"><span class="annottext">buf :: Buffer Word8
</span><a href="#local-6989586621679556793"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556792"><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679556792"><span class="hs-identifier hs-var">raw</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556791"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556791"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556790"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556790"><span class="hs-identifier hs-var">_r</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556789"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556789"><span class="hs-identifier hs-var">sz</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufOffset :: forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556788"><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556788"><span class="hs-identifier hs-var">bff</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-970"></span><span>             </span><span id="local-6989586621679556787"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556787"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679556786"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556786"><span class="hs-identifier hs-var">so_far</span></a></span></span><span> </span><span id="local-6989586621679556785"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556785"><span class="hs-identifier hs-var">count</span></a></span></span><span>
</span><span id="line-971"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556785"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E"><span class="hs-operator hs-var">&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556789"><span class="hs-identifier hs-var">sz</span></a></span><span>
</span><span id="line-972"></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-973"></span><span>        </span><span id="local-6989586621679556784"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556784"><span class="hs-identifier hs-var">bytes_read</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Int -&gt; Word64 -&gt; Int -&gt; IO Int
forall dev. RawIO dev =&gt; dev -&gt; Int -&gt; Word64 -&gt; Int -&gt; IO Int
</span><a href="#local-6989586621679556783"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679556806"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556788"><span class="hs-identifier hs-var">bff</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556785"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-974"></span><span>        </span><span class="hs-comment">-- bytes_read includes so_far (content that was in the buffer)</span><span>
</span><span id="line-975"></span><span>        </span><span class="hs-comment">-- but that is already accounted for in the old offset, so don't</span><span>
</span><span id="line-976"></span><span>        </span><span class="hs-comment">-- count it twice.</span><span>
</span><span id="line-977"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679556778"><span class="annot"><span class="annottext">buf1 :: Buffer Word8
</span><a href="#local-6989586621679556778"><span class="hs-identifier hs-var hs-var">buf1</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Word8 -&gt; Buffer Word8
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAddOffset"><span class="hs-identifier hs-var">bufferAddOffset</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Int
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">(Int -&gt; Int) -&gt; Int -&gt; Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556784"><span class="hs-identifier hs-var">bytes_read</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556786"><span class="hs-identifier hs-var">so_far</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556793"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-978"></span><span>        </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556804"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556778"><span class="hs-identifier hs-var">buf1</span></a></span><span>
</span><span id="line-979"></span><span>        </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;bufReadEmpty1.1: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; String
forall a. Buffer a -&gt; String
</span><a href="GHC.IO.Buffer.html#summaryBuffer"><span class="hs-identifier hs-var">summaryBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556778"><span class="hs-identifier hs-var">buf1</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; read:&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556784"><span class="hs-identifier hs-var">bytes_read</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-980"></span><span>        </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556784"><span class="hs-identifier hs-var">bytes_read</span></a></span><span>
</span><span id="line-981"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-982"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621679556777"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556777"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679556776"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556776"><span class="hs-identifier hs-var">buf'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Buffer Word8 -&gt; IO (Int, Buffer Word8)
forall dev.
BufferedIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Int, Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#fillReadBuffer"><span class="hs-identifier hs-var">Buffered.fillReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679556806"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556793"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-983"></span><span>        </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556804"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556776"><span class="hs-identifier hs-var">buf'</span></a></span><span>
</span><span id="line-984"></span><span>        </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556777"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-comment">-- end of file reached</span><span>
</span><span id="line-985"></span><span>            </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556786"><span class="hs-identifier hs-var">so_far</span></a></span><span>
</span><span id="line-986"></span><span>            </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadNonEmpty"><span class="hs-identifier hs-var">bufReadNonEmpty</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556824"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556776"><span class="hs-identifier hs-var">buf'</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556787"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556786"><span class="hs-identifier hs-var">so_far</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556785"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-987"></span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-988"></span><span>  </span><span class="hs-comment">-- Read @bytes@ byte into ptr. Repeating the read until either zero</span><span>
</span><span id="line-989"></span><span>  </span><span class="hs-comment">-- bytes where read, or we are done reading.</span><span>
</span><span id="line-990"></span><span>  </span><span id="local-6989586621679557935"><span class="annot"><a href="#local-6989586621679556783"><span class="hs-identifier hs-type">loop</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Device.html#RawIO"><span class="hs-identifier hs-type">RawIO.RawIO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679557935"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">=&gt;</span><span> </span><span class="annot"><a href="#local-6989586621679557935"><span class="hs-identifier hs-type">dev</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Word.html#Word64"><span class="hs-identifier hs-type">Word64</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span></span><span>
</span><span id="line-991"></span><span>  </span><span id="local-6989586621679556783"><span class="annot"><span class="annottext">loop :: forall dev. RawIO dev =&gt; dev -&gt; Int -&gt; Word64 -&gt; Int -&gt; IO Int
</span><a href="#local-6989586621679556783"><span class="hs-identifier hs-var hs-var">loop</span></a></span></span><span> </span><span id="local-6989586621679556747"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679556747"><span class="hs-identifier hs-var">dev</span></a></span></span><span> </span><span id="local-6989586621679556746"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556746"><span class="hs-identifier hs-var">delta</span></a></span></span><span> </span><span id="local-6989586621679556745"><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556745"><span class="hs-identifier hs-var">off</span></a></span></span><span> </span><span id="local-6989586621679556744"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556744"><span class="hs-identifier hs-var">bytes</span></a></span></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556744"><span class="hs-identifier hs-var">bytes</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C%3D"><span class="hs-operator hs-var">&lt;=</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556786"><span class="hs-identifier hs-var">so_far</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556746"><span class="hs-identifier hs-var">delta</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-992"></span><span>  </span><span class="annot"><a href="#local-6989586621679556783"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span id="local-6989586621679556743"><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679556743"><span class="hs-identifier hs-var">dev</span></a></span></span><span> </span><span id="local-6989586621679556742"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556742"><span class="hs-identifier hs-var">delta</span></a></span></span><span> </span><span id="local-6989586621679556741"><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556741"><span class="hs-identifier hs-var">off</span></a></span></span><span> </span><span id="local-6989586621679556740"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556740"><span class="hs-identifier hs-var">bytes</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-993"></span><span>    </span><span id="local-6989586621679556739"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556739"><span class="hs-identifier hs-var">r</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
forall a. RawIO a =&gt; a -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Device.html#read"><span class="hs-identifier hs-var">RawIO.read</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679556743"><span class="hs-identifier hs-var">dev</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556787"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr Word8
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556742"><span class="hs-identifier hs-var">delta</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556741"><span class="hs-identifier hs-var">off</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556740"><span class="hs-identifier hs-var">bytes</span></a></span><span>
</span><span id="line-994"></span><span>    </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556787"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; - loop read@&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556742"><span class="hs-identifier hs-var">delta</span></a></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;: &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556739"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-995"></span><span>    </span><span class="annot"><span class="annottext">String -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#debugIO"><span class="hs-identifier hs-var">debugIO</span></a></span><span> </span><span class="annot"><span class="annottext">(String -&gt; IO ()) -&gt; String -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;next:&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556742"><span class="hs-identifier hs-var">delta</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556739"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot; - left:&quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; String
forall a. Show a =&gt; a -&gt; String
</span><a href="GHC.Show.html#show"><span class="hs-identifier hs-var">show</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556740"><span class="hs-identifier hs-var">bytes</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556739"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-996"></span><span>    </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556739"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-997"></span><span>        </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556786"><span class="hs-identifier hs-var">so_far</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556742"><span class="hs-identifier hs-var">delta</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-998"></span><span>        </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Int -&gt; Word64 -&gt; Int -&gt; IO Int
forall dev. RawIO dev =&gt; dev -&gt; Int -&gt; Word64 -&gt; Int -&gt; IO Int
</span><a href="#local-6989586621679556783"><span class="hs-identifier hs-var">loop</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679556743"><span class="hs-identifier hs-var">dev</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556742"><span class="hs-identifier hs-var">delta</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556739"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556741"><span class="hs-identifier hs-var">off</span></a></span><span> </span><span class="annot"><span class="annottext">Word64 -&gt; Word64 -&gt; Word64
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Word64
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556739"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556740"><span class="hs-identifier hs-var">bytes</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556739"><span class="hs-identifier hs-var">r</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-999"></span><span>
</span><span id="line-1000"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-1001"></span><span class="hs-comment">-- hGetBufSome</span><span>
</span><span id="line-1002"></span><span>
</span><span id="line-1003"></span><span class="hs-comment">-- | 'hGetBufSome' @hdl buf count@ reads data from the handle @hdl@</span><span>
</span><span id="line-1004"></span><span class="hs-comment">-- into the buffer @buf@.  If there is any data available to read,</span><span>
</span><span id="line-1005"></span><span class="hs-comment">-- then 'hGetBufSome' returns it immediately; it only blocks if there</span><span>
</span><span id="line-1006"></span><span class="hs-comment">-- is no data to be read.</span><span>
</span><span id="line-1007"></span><span class="hs-comment">--</span><span>
</span><span id="line-1008"></span><span class="hs-comment">-- It returns the number of bytes actually read.  This may be zero if</span><span>
</span><span id="line-1009"></span><span class="hs-comment">-- EOF was reached before any data was read (or if @count@ is zero).</span><span>
</span><span id="line-1010"></span><span class="hs-comment">--</span><span>
</span><span id="line-1011"></span><span class="hs-comment">-- 'hGetBufSome' never raises an EOF exception, instead it returns a value</span><span>
</span><span id="line-1012"></span><span class="hs-comment">-- smaller than @count@.</span><span>
</span><span id="line-1013"></span><span class="hs-comment">--</span><span>
</span><span id="line-1014"></span><span class="hs-comment">-- If the handle is a pipe or socket, and the writing end</span><span>
</span><span id="line-1015"></span><span class="hs-comment">-- is closed, 'hGetBufSome' will behave as if EOF was reached.</span><span>
</span><span id="line-1016"></span><span class="hs-comment">--</span><span>
</span><span id="line-1017"></span><span class="hs-comment">-- 'hGetBufSome' ignores the prevailing 'System.IO.TextEncoding' and</span><span>
</span><span id="line-1018"></span><span class="hs-comment">-- 'NewlineMode' on the 'Handle', and reads bytes directly.</span><span>
</span><span id="line-1019"></span><span>
</span><span id="line-1020"></span><span id="local-6989586621679556737"><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetBufSome"><span class="hs-identifier hs-type">hGetBufSome</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679556737"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span></span><span>
</span><span id="line-1021"></span><span id="hGetBufSome"><span class="annot"><span class="annottext">hGetBufSome :: forall a. Handle -&gt; Ptr a -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#hGetBufSome"><span class="hs-identifier hs-var hs-var">hGetBufSome</span></a></span></span><span> </span><span id="local-6989586621679556730"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679556730"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679556729"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679556729"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679556728"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556728"><span class="hs-identifier hs-var">count</span></a></span></span><span>
</span><span id="line-1022"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556728"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-1023"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556728"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span>  </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; Int -&gt; IO Int
forall a. Handle -&gt; String -&gt; Int -&gt; IO a
</span><a href="GHC.IO.Handle.Text.html#illegalBufferSize"><span class="hs-identifier hs-var">illegalBufferSize</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679556730"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetBufSome&quot;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556728"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-1024"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1025"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; Handle -&gt; (Handle__ -&gt; IO Int) -&gt; IO Int
forall a. String -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle_"><span class="hs-identifier hs-var">wantReadableHandle_</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetBufSome&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679556730"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO Int) -&gt; IO Int) -&gt; (Handle__ -&gt; IO Int) -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679556727"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679556727"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679556695"><span id="local-6989586621679556696"><span id="local-6989586621679556697"><span id="local-6989586621679556698"><span id="local-6989586621679556699"><span id="local-6989586621679556700"><span id="local-6989586621679556701"><span id="local-6989586621679556702"><span id="local-6989586621679556703"><span id="local-6989586621679556704"><span id="local-6989586621679556705"><span id="local-6989586621679556706"><span id="local-6989586621679556707"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679556695"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1026"></span><span>         </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushCharReadBuffer"><span class="hs-identifier hs-var">flushCharReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556727"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-1027"></span><span>         </span><span id="local-6989586621679556694"><span class="annot"><span class="annottext">buf :: Buffer Word8
</span><a href="#local-6989586621679556694"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556693"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556693"><span class="hs-identifier hs-var">sz</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufOffset :: forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556692"><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556692"><span class="hs-identifier hs-var">offset</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556705"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-1028"></span><span>         </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556694"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-1029"></span><span>            </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556728"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E"><span class="hs-operator hs-var">&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556693"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="hs-keyword">of</span><span>  </span><span class="hs-comment">-- large read? optimize it with a little special case:</span><span>
</span><span id="line-1030"></span><span>                    </span><span class="annot"><span class="annottext">Bool
</span><a href="../../ghc-prim/src/GHC.Types.html#True"><span class="hs-identifier hs-var">True</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span id="local-6989586621679556691"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556691"><span class="hs-identifier hs-var">bytes</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
forall a. RawIO a =&gt; a -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Device.html#read"><span class="hs-identifier hs-var">RawIO.read</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679556707"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679556729"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556692"><span class="hs-identifier hs-var">offset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556728"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-1031"></span><span>                               </span><span class="hs-comment">-- Update buffer with actual bytes written.</span><span>
</span><span id="line-1032"></span><span>                               </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556705"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">(Buffer Word8 -&gt; IO ()) -&gt; Buffer Word8 -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Word8 -&gt; Buffer Word8
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAddOffset"><span class="hs-identifier hs-var">bufferAddOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556691"><span class="hs-identifier hs-var">bytes</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556694"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-1033"></span><span>                               </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556691"><span class="hs-identifier hs-var">bytes</span></a></span><span>
</span><span id="line-1034"></span><span>                    </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">(</span><span id="local-6989586621679556690"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556690"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679556689"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556689"><span class="hs-identifier hs-var">buf'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Buffer Word8 -&gt; IO (Int, Buffer Word8)
forall dev.
BufferedIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Int, Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#fillReadBuffer"><span class="hs-identifier hs-var">Buffered.fillReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679556707"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556694"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-1035"></span><span>                            </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556690"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-1036"></span><span>                               </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-1037"></span><span>                               </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556705"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556689"><span class="hs-identifier hs-var">buf'</span></a></span><span>
</span><span id="line-1038"></span><span>                                       </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadNBNonEmpty"><span class="hs-identifier hs-var">bufReadNBNonEmpty</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556727"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556689"><span class="hs-identifier hs-var">buf'</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679556729"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Ord a =&gt; a -&gt; a -&gt; a
</span><a href="../../ghc-prim/src/GHC.Classes.html#min"><span class="hs-identifier hs-var">min</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556690"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556728"><span class="hs-identifier hs-var">count</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1039"></span><span>                                        </span><span class="hs-comment">-- new count is  (min r count), so</span><span>
</span><span id="line-1040"></span><span>                                        </span><span class="hs-comment">-- that bufReadNBNonEmpty will not</span><span>
</span><span id="line-1041"></span><span>                                        </span><span class="hs-comment">-- issue another read.</span><span>
</span><span id="line-1042"></span><span>            </span><span class="hs-keyword">else</span><span>
</span><span id="line-1043"></span><span>              </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679556685"><span class="annot"><span class="annottext">count' :: Int
</span><a href="#local-6989586621679556685"><span class="hs-identifier hs-var hs-var">count'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Ord a =&gt; a -&gt; a -&gt; a
</span><a href="../../ghc-prim/src/GHC.Classes.html#min"><span class="hs-identifier hs-var">min</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556728"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Int
forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufferElems"><span class="hs-identifier hs-var">bufferElems</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556694"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1044"></span><span>              </span><span class="hs-keyword">in</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadNBNonEmpty"><span class="hs-identifier hs-var">bufReadNBNonEmpty</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556727"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556694"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679556729"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556685"><span class="hs-identifier hs-var">count'</span></a></span><span>
</span><span id="line-1045"></span><span>
</span><span id="line-1046"></span><span class="hs-comment">-- | 'hGetBufNonBlocking' @hdl buf count@ reads data from the handle @hdl@</span><span>
</span><span id="line-1047"></span><span class="hs-comment">-- into the buffer @buf@ until either EOF is reached, or</span><span>
</span><span id="line-1048"></span><span class="hs-comment">-- @count@ 8-bit bytes have been read, or there is no more data available</span><span>
</span><span id="line-1049"></span><span class="hs-comment">-- to read immediately.</span><span>
</span><span id="line-1050"></span><span class="hs-comment">--</span><span>
</span><span id="line-1051"></span><span class="hs-comment">-- 'hGetBufNonBlocking' is identical to 'hGetBuf', except that it will</span><span>
</span><span id="line-1052"></span><span class="hs-comment">-- never block waiting for data to become available, instead it returns</span><span>
</span><span id="line-1053"></span><span class="hs-comment">-- only whatever data is available.  To wait for data to arrive before</span><span>
</span><span id="line-1054"></span><span class="hs-comment">-- calling 'hGetBufNonBlocking', use 'hWaitForInput'.</span><span>
</span><span id="line-1055"></span><span class="hs-comment">--</span><span>
</span><span id="line-1056"></span><span class="hs-comment">-- If the handle is a pipe or socket, and the writing end</span><span>
</span><span id="line-1057"></span><span class="hs-comment">-- is closed, 'hGetBufNonBlocking' will behave as if EOF was reached.</span><span>
</span><span id="line-1058"></span><span class="hs-comment">--</span><span>
</span><span id="line-1059"></span><span class="hs-comment">-- 'hGetBufNonBlocking' ignores the prevailing 'System.IO.TextEncoding' and</span><span>
</span><span id="line-1060"></span><span class="hs-comment">-- 'NewlineMode' on the 'Handle', and reads bytes directly.</span><span>
</span><span id="line-1061"></span><span class="hs-comment">--</span><span>
</span><span id="line-1062"></span><span class="hs-comment">-- NOTE: on Windows, this function does not work correctly; it</span><span>
</span><span id="line-1063"></span><span class="hs-comment">-- behaves identically to 'hGetBuf'.</span><span>
</span><span id="line-1064"></span><span>
</span><span id="line-1065"></span><span id="local-6989586621679556684"><span class="annot"><a href="GHC.IO.Handle.Text.html#hGetBufNonBlocking"><span class="hs-identifier hs-type">hGetBufNonBlocking</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679556684"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span></span><span>
</span><span id="line-1066"></span><span id="hGetBufNonBlocking"><span class="annot"><span class="annottext">hGetBufNonBlocking :: forall a. Handle -&gt; Ptr a -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#hGetBufNonBlocking"><span class="hs-identifier hs-var hs-var">hGetBufNonBlocking</span></a></span></span><span> </span><span id="local-6989586621679556677"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679556677"><span class="hs-identifier hs-var">h</span></a></span></span><span> </span><span class="hs-glyph">!</span><span id="local-6989586621679556676"><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679556676"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679556675"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556675"><span class="hs-identifier hs-var">count</span></a></span></span><span>
</span><span id="line-1067"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556675"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-1068"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556675"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span>  </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Handle -&gt; String -&gt; Int -&gt; IO Int
forall a. Handle -&gt; String -&gt; Int -&gt; IO a
</span><a href="GHC.IO.Handle.Text.html#illegalBufferSize"><span class="hs-identifier hs-var">illegalBufferSize</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679556677"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetBufNonBlocking&quot;</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556675"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-1069"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1070"></span><span>      </span><span class="annot"><span class="annottext">String -&gt; Handle -&gt; (Handle__ -&gt; IO Int) -&gt; IO Int
forall a. String -&gt; Handle -&gt; (Handle__ -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Handle.Internals.html#wantReadableHandle_"><span class="hs-identifier hs-var">wantReadableHandle_</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;hGetBufNonBlocking&quot;</span></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679556677"><span class="hs-identifier hs-var">h</span></a></span><span> </span><span class="annot"><span class="annottext">((Handle__ -&gt; IO Int) -&gt; IO Int) -&gt; (Handle__ -&gt; IO Int) -&gt; IO Int
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span> </span><span id="local-6989586621679556674"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679556674"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679556655"><span id="local-6989586621679556656"><span id="local-6989586621679556657"><span id="local-6989586621679556658"><span id="local-6989586621679556659"><span id="local-6989586621679556660"><span id="local-6989586621679556661"><span id="local-6989586621679556662"><span id="local-6989586621679556663"><span id="local-6989586621679556664"><span id="local-6989586621679556665"><span id="local-6989586621679556666"><span id="local-6989586621679556667"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679556655"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1071"></span><span>         </span><span class="annot"><span class="annottext">Handle__ -&gt; IO ()
</span><a href="GHC.IO.Handle.Internals.html#flushCharReadBuffer"><span class="hs-identifier hs-var">flushCharReadBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556674"><span class="hs-identifier hs-var">h_</span></a></span><span>
</span><span id="line-1072"></span><span>         </span><span id="local-6989586621679556654"><span class="annot"><span class="annottext">buf :: Buffer Word8
</span><a href="#local-6989586621679556654"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556653"><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679556653"><span class="hs-identifier hs-var">raw</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556652"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556652"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556651"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556651"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556650"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556650"><span class="hs-identifier hs-var">sz</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1073"></span><span>            </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; IO (Buffer Word8)
forall a. IORef a -&gt; IO a
</span><a href="GHC.IORef.html#readIORef"><span class="hs-identifier hs-var">readIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556665"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span>
</span><span id="line-1074"></span><span>         </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Buffer Word8 -&gt; Bool
forall e. Buffer e -&gt; Bool
</span><a href="GHC.IO.Buffer.html#isEmptyBuffer"><span class="hs-identifier hs-var">isEmptyBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556654"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-1075"></span><span>            </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadNBEmpty"><span class="hs-identifier hs-var">bufReadNBEmpty</span></a></span><span>    </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556674"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556654"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679556676"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556675"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-1076"></span><span>            </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadNBNonEmpty"><span class="hs-identifier hs-var">bufReadNBNonEmpty</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556674"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556654"><span class="hs-identifier hs-var">buf</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr a -&gt; Ptr Word8
forall a b. Ptr a -&gt; Ptr b
</span><a href="GHC.Ptr.html#castPtr"><span class="hs-identifier hs-var">castPtr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr a
</span><a href="#local-6989586621679556676"><span class="hs-identifier hs-var">ptr</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556675"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-1077"></span><span>
</span><span id="line-1078"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#bufReadNBEmpty"><span class="hs-identifier hs-type">bufReadNBEmpty</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-1079"></span><span id="bufReadNBEmpty"><span class="annot"><span class="annottext">bufReadNBEmpty :: Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadNBEmpty"><span class="hs-identifier hs-var hs-var">bufReadNBEmpty</span></a></span></span><span>   </span><span id="local-6989586621679556648"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679556648"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679556616"><span id="local-6989586621679556617"><span id="local-6989586621679556618"><span id="local-6989586621679556619"><span id="local-6989586621679556620"><span id="local-6989586621679556621"><span id="local-6989586621679556622"><span id="local-6989586621679556623"><span id="local-6989586621679556624"><span id="local-6989586621679556625"><span id="local-6989586621679556626"><span id="local-6989586621679556627"><span id="local-6989586621679556628"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679556616"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span>
</span><span id="line-1080"></span><span>                 </span><span id="local-6989586621679556615"><span class="annot"><span class="annottext">buf :: Buffer Word8
</span><a href="#local-6989586621679556615"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556614"><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679556614"><span class="hs-identifier hs-var">raw</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556613"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556613"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556612"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556612"><span class="hs-identifier hs-var">_r</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556611"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556611"><span class="hs-identifier hs-var">sz</span></a></span></span><span>
</span><span id="line-1081"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufOffset :: forall e. Buffer e -&gt; Word64
</span><a href="GHC.IO.Buffer.html#bufOffset"><span class="hs-identifier hs-var">bufOffset</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556610"><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556610"><span class="hs-identifier hs-var">offset</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1082"></span><span>                 </span><span id="local-6989586621679556609"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556609"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679556608"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556608"><span class="hs-identifier hs-var">so_far</span></a></span></span><span> </span><span id="local-6989586621679556607"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556607"><span class="hs-identifier hs-var">count</span></a></span></span><span>
</span><span id="line-1083"></span><span>  </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556607"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3E"><span class="hs-operator hs-var">&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556611"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1084"></span><span>       </span><span id="local-6989586621679556606"><span class="annot"><span class="annottext">Maybe Int
</span><a href="#local-6989586621679556606"><span class="hs-identifier hs-var">m</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO (Maybe Int)
forall a.
RawIO a =&gt;
a -&gt; Ptr Word8 -&gt; Word64 -&gt; Int -&gt; IO (Maybe Int)
</span><a href="GHC.IO.Device.html#readNonBlocking"><span class="hs-identifier hs-var">RawIO.readNonBlocking</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679556628"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556609"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Word64
</span><a href="#local-6989586621679556610"><span class="hs-identifier hs-var">offset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556607"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-1085"></span><span>       </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe Int
</span><a href="#local-6989586621679556606"><span class="hs-identifier hs-var">m</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1086"></span><span>         </span><span class="annot"><span class="annottext">Maybe Int
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556608"><span class="hs-identifier hs-var">so_far</span></a></span><span>
</span><span id="line-1087"></span><span>         </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679556604"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556604"><span class="hs-identifier hs-var">n</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-comment">-- Update buffer with actual bytes written.</span><span>
</span><span id="line-1088"></span><span>                       </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556626"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">(Buffer Word8 -&gt; IO ()) -&gt; Buffer Word8 -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24%21"><span class="hs-operator hs-var">$!</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Buffer Word8 -&gt; Buffer Word8
forall e. Int -&gt; Buffer e -&gt; Buffer e
</span><a href="GHC.IO.Buffer.html#bufferAddOffset"><span class="hs-identifier hs-var">bufferAddOffset</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556604"><span class="hs-identifier hs-var">n</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556615"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-1089"></span><span>                       </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556608"><span class="hs-identifier hs-var">so_far</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556604"><span class="hs-identifier hs-var">n</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1090"></span><span>
</span><span id="line-1091"></span><span> </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1092"></span><span>    </span><span class="hs-comment">--  buf &lt;- readIORef haByteBuffer</span><span>
</span><span id="line-1093"></span><span>     </span><span class="hs-special">(</span><span id="local-6989586621679556603"><span class="annot"><span class="annottext">Maybe Int
</span><a href="#local-6989586621679556603"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621679556602"><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556602"><span class="hs-identifier hs-var">buf'</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">dev -&gt; Buffer Word8 -&gt; IO (Maybe Int, Buffer Word8)
forall dev.
BufferedIO dev =&gt;
dev -&gt; Buffer Word8 -&gt; IO (Maybe Int, Buffer Word8)
</span><a href="GHC.IO.BufferedIO.html#fillReadBuffer0"><span class="hs-identifier hs-var">Buffered.fillReadBuffer0</span></a></span><span> </span><span class="annot"><span class="annottext">dev
</span><a href="#local-6989586621679556628"><span class="hs-identifier hs-var">haDevice</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556615"><span class="hs-identifier hs-var">buf</span></a></span><span>
</span><span id="line-1094"></span><span>     </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">Maybe Int
</span><a href="#local-6989586621679556603"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-1095"></span><span>       </span><span class="annot"><span class="annottext">Maybe Int
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556608"><span class="hs-identifier hs-var">so_far</span></a></span><span>
</span><span id="line-1096"></span><span>       </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556608"><span class="hs-identifier hs-var">so_far</span></a></span><span>
</span><span id="line-1097"></span><span>       </span><span class="annot"><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621679556600"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556600"><span class="hs-identifier hs-var">r'</span></a></span></span><span>  </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1098"></span><span>         </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556626"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556602"><span class="hs-identifier hs-var">buf'</span></a></span><span>
</span><span id="line-1099"></span><span>         </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadNBNonEmpty"><span class="hs-identifier hs-var">bufReadNBNonEmpty</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556648"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556602"><span class="hs-identifier hs-var">buf'</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556609"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556608"><span class="hs-identifier hs-var">so_far</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Ord a =&gt; a -&gt; a -&gt; a
</span><a href="../../ghc-prim/src/GHC.Classes.html#min"><span class="hs-identifier hs-var">min</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556607"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556600"><span class="hs-identifier hs-var">r'</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1100"></span><span>                          </span><span class="hs-comment">-- NOTE: new count is    min count r'</span><span>
</span><span id="line-1101"></span><span>                          </span><span class="hs-comment">-- so we will just copy the contents of the</span><span>
</span><span id="line-1102"></span><span>                          </span><span class="hs-comment">-- buffer in the recursive call, and not</span><span>
</span><span id="line-1103"></span><span>                          </span><span class="hs-comment">-- loop again.</span><span>
</span><span id="line-1104"></span><span>
</span><span id="line-1105"></span><span>
</span><span id="line-1106"></span><span class="annot"><a href="GHC.IO.Handle.Text.html#bufReadNBNonEmpty"><span class="hs-identifier hs-type">bufReadNBNonEmpty</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="GHC.Word.html#Word8"><span class="hs-identifier hs-type">Word8</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span>
</span><span id="line-1107"></span><span id="bufReadNBNonEmpty"><span class="annot"><span class="annottext">bufReadNBNonEmpty :: Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadNBNonEmpty"><span class="hs-identifier hs-var hs-var">bufReadNBNonEmpty</span></a></span></span><span> </span><span id="local-6989586621679556599"><span class="annot"><span class="annottext">h_ :: Handle__
</span><a href="#local-6989586621679556599"><span class="hs-identifier hs-var">h_</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle__"><span class="hs-identifier hs-type">Handle__</span></a></span><span class="hs-special">{</span><span id="local-6989586621679556571"><span id="local-6989586621679556572"><span id="local-6989586621679556573"><span id="local-6989586621679556574"><span id="local-6989586621679556575"><span id="local-6989586621679556576"><span id="local-6989586621679556577"><span id="local-6989586621679556578"><span id="local-6989586621679556579"><span id="local-6989586621679556580"><span id="local-6989586621679556581"><span id="local-6989586621679556582"><span id="local-6989586621679556583"><span class="annot"><span class="annottext">dev
Maybe (MVar Handle__)
Maybe (TextEncoder enc_state)
Maybe (TextDecoder dec_state)
Maybe TextEncoding
IORef (dec_state, Buffer Word8)
IORef (Buffer Char)
IORef (Buffer Word8)
IORef (BufferList Char)
BufferMode
HandleType
Newline
haOtherSide :: Maybe (MVar Handle__)
haOutputNL :: Newline
haInputNL :: Newline
haCodec :: Maybe TextEncoding
haDecoder :: Maybe (TextDecoder dec_state)
haEncoder :: Maybe (TextEncoder enc_state)
haBuffers :: IORef (BufferList Char)
haCharBuffer :: IORef (Buffer Char)
haLastDecode :: IORef (dec_state, Buffer Word8)
haBufferMode :: BufferMode
haByteBuffer :: IORef (Buffer Word8)
haType :: HandleType
haDevice :: dev
haType :: Handle__ -&gt; HandleType
haOutputNL :: Handle__ -&gt; Newline
haOtherSide :: Handle__ -&gt; Maybe (MVar Handle__)
haLastDecode :: ()
haInputNL :: Handle__ -&gt; Newline
haEncoder :: ()
haDevice :: ()
haDecoder :: ()
haCodec :: Handle__ -&gt; Maybe TextEncoding
haCharBuffer :: Handle__ -&gt; IORef (Buffer Char)
haByteBuffer :: Handle__ -&gt; IORef (Buffer Word8)
haBuffers :: Handle__ -&gt; IORef (BufferList Char)
haBufferMode :: Handle__ -&gt; BufferMode
</span><a href="#local-6989586621679556571"><span class="hs-glyph hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var hs-var">..</span></a></span></span></span></span></span></span></span></span></span></span></span></span></span></span><span class="hs-special">}</span><span>
</span><span id="line-1108"></span><span>                  </span><span id="local-6989586621679556570"><span class="annot"><span class="annottext">buf :: Buffer Word8
</span><a href="#local-6989586621679556570"><span class="hs-identifier hs-var">buf</span></a></span></span><span class="hs-glyph">@</span><span class="annot"><a href="GHC.IO.Buffer.html#Buffer"><span class="hs-identifier hs-type">Buffer</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufRaw :: forall e. Buffer e -&gt; RawBuffer e
</span><a href="GHC.IO.Buffer.html#bufRaw"><span class="hs-identifier hs-var">bufRaw</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556569"><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679556569"><span class="hs-identifier hs-var">raw</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufR :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556568"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556568"><span class="hs-identifier hs-var">w</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556567"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556567"><span class="hs-identifier hs-var">r</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufSize :: forall e. Buffer e -&gt; Int
</span><a href="GHC.IO.Buffer.html#bufSize"><span class="hs-identifier hs-var">bufSize</span></a></span><span class="hs-glyph">=</span><span id="local-6989586621679556566"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556566"><span class="hs-identifier hs-var">sz</span></a></span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1109"></span><span>                  </span><span id="local-6989586621679556565"><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556565"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679556564"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556564"><span class="hs-identifier hs-var">so_far</span></a></span></span><span> </span><span id="local-6989586621679556563"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556563"><span class="hs-identifier hs-var">count</span></a></span></span><span>
</span><span id="line-1110"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1111"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679556561"><span class="annot"><span class="annottext">avail :: Int
</span><a href="#local-6989586621679556561"><span class="hs-identifier hs-var hs-var">avail</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556568"><span class="hs-identifier hs-var">w</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556567"><span class="hs-identifier hs-var">r</span></a></span><span>
</span><span id="line-1112"></span><span>        </span><span class="hs-comment">-- We use &lt; instead of &lt;= because for count == avail</span><span>
</span><span id="line-1113"></span><span>        </span><span class="hs-comment">-- we need to reset bufL and bufR to zero.</span><span>
</span><span id="line-1114"></span><span>        </span><span class="hs-comment">-- See also [INVARIANTS on Buffers] in Buffer.hs</span><span>
</span><span id="line-1115"></span><span>        </span><span class="hs-keyword">if</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556563"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Ord a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3C"><span class="hs-operator hs-var">&lt;</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556561"><span class="hs-identifier hs-var">avail</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1116"></span><span>           </span><span class="hs-keyword">then</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1117"></span><span>                </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; RawBuffer Word8 -&gt; Int -&gt; Int -&gt; IO ()
forall e. Ptr e -&gt; RawBuffer e -&gt; Int -&gt; Int -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#copyFromRawBuffer"><span class="hs-identifier hs-var">copyFromRawBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556565"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679556569"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556567"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556563"><span class="hs-identifier hs-var">count</span></a></span><span>
</span><span id="line-1118"></span><span>                </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556581"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556570"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556567"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556563"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1119"></span><span>                </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556564"><span class="hs-identifier hs-var">so_far</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556563"><span class="hs-identifier hs-var">count</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1120"></span><span>           </span><span class="hs-keyword">else</span><span> </span><span class="hs-keyword">do</span><span>
</span><span id="line-1121"></span><span>
</span><span id="line-1122"></span><span>        </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; RawBuffer Word8 -&gt; Int -&gt; Int -&gt; IO ()
forall e. Ptr e -&gt; RawBuffer e -&gt; Int -&gt; Int -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#copyFromRawBuffer"><span class="hs-identifier hs-var">copyFromRawBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556565"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer Word8
</span><a href="#local-6989586621679556569"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556567"><span class="hs-identifier hs-var">r</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556561"><span class="hs-identifier hs-var">avail</span></a></span><span>
</span><span id="line-1123"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679556560"><span class="annot"><span class="annottext">buf' :: Buffer Word8
</span><a href="#local-6989586621679556560"><span class="hs-identifier hs-var hs-var">buf'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556570"><span class="hs-identifier hs-var">buf</span></a></span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">bufR :: Int
</span><a href="GHC.IO.Buffer.html#bufR"><span class="hs-identifier hs-var">bufR</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">bufL :: Int
</span><a href="GHC.IO.Buffer.html#bufL"><span class="hs-identifier hs-var">bufL</span></a></span><span class="hs-glyph">=</span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-1124"></span><span>        </span><span class="annot"><span class="annottext">IORef (Buffer Word8) -&gt; Buffer Word8 -&gt; IO ()
forall a. IORef a -&gt; a -&gt; IO ()
</span><a href="GHC.IORef.html#writeIORef"><span class="hs-identifier hs-var">writeIORef</span></a></span><span> </span><span class="annot"><span class="annottext">IORef (Buffer Word8)
</span><a href="#local-6989586621679556581"><span class="hs-identifier hs-var">haByteBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556560"><span class="hs-identifier hs-var">buf'</span></a></span><span>
</span><span id="line-1125"></span><span>        </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621679556558"><span class="annot"><span class="annottext">remaining :: Int
</span><a href="#local-6989586621679556558"><span class="hs-identifier hs-var hs-var">remaining</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556563"><span class="hs-identifier hs-var">count</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#-"><span class="hs-glyph hs-var">-</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556561"><span class="hs-identifier hs-var">avail</span></a></span><span>
</span><span id="line-1126"></span><span>            </span><span id="local-6989586621679556556"><span class="annot"><span class="annottext">so_far' :: Int
</span><a href="#local-6989586621679556556"><span class="hs-identifier hs-var hs-var">so_far'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556564"><span class="hs-identifier hs-var">so_far</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Int
forall a. Num a =&gt; a -&gt; a -&gt; a
</span><a href="GHC.Num.html#%2B"><span class="hs-operator hs-var">+</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556561"><span class="hs-identifier hs-var">avail</span></a></span><span>
</span><span id="line-1127"></span><span>            </span><span id="local-6989586621679556555"><span class="annot"><span class="annottext">ptr' :: Ptr b
</span><a href="#local-6989586621679556555"><span class="hs-identifier hs-var hs-var">ptr'</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ptr Word8
</span><a href="#local-6989586621679556565"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8 -&gt; Int -&gt; Ptr b
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556561"><span class="hs-identifier hs-var">avail</span></a></span><span>
</span><span id="line-1128"></span><span>
</span><span id="line-1129"></span><span>        </span><span class="hs-keyword">if</span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556558"><span class="hs-identifier hs-var">remaining</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; Bool
forall a. Eq a =&gt; a -&gt; a -&gt; Bool
</span><a href="../../ghc-prim/src/GHC.Classes.html#%3D%3D"><span class="hs-operator hs-var">==</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">0</span></span><span>
</span><span id="line-1130"></span><span>           </span><span class="hs-keyword">then</span><span> </span><span class="annot"><span class="annottext">Int -&gt; IO Int
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556556"><span class="hs-identifier hs-var">so_far'</span></a></span><span>
</span><span id="line-1131"></span><span>           </span><span class="hs-keyword">else</span><span> </span><span class="annot"><span class="annottext">Handle__ -&gt; Buffer Word8 -&gt; Ptr Word8 -&gt; Int -&gt; Int -&gt; IO Int
</span><a href="GHC.IO.Handle.Text.html#bufReadNBEmpty"><span class="hs-identifier hs-var">bufReadNBEmpty</span></a></span><span> </span><span class="annot"><span class="annottext">Handle__
</span><a href="#local-6989586621679556599"><span class="hs-identifier hs-var">h_</span></a></span><span> </span><span class="annot"><span class="annottext">Buffer Word8
</span><a href="#local-6989586621679556560"><span class="hs-identifier hs-var">buf'</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr Word8
forall {b}. Ptr b
</span><a href="#local-6989586621679556555"><span class="hs-identifier hs-var">ptr'</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556556"><span class="hs-identifier hs-var">so_far'</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556558"><span class="hs-identifier hs-var">remaining</span></a></span><span>
</span><span id="line-1132"></span><span>
</span><span id="line-1133"></span><span class="hs-comment">-- ---------------------------------------------------------------------------</span><span>
</span><span id="line-1134"></span><span class="hs-comment">-- memcpy wrappers</span><span>
</span><span id="line-1135"></span><span>
</span><span id="line-1136"></span><span id="local-6989586621679557957"><span class="annot"><a href="GHC.IO.Handle.Text.html#copyToRawBuffer"><span class="hs-identifier hs-type">copyToRawBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawBuffer"><span class="hs-identifier hs-type">RawBuffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679557957"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679557957"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-1137"></span><span id="copyToRawBuffer"><span class="annot"><span class="annottext">copyToRawBuffer :: forall e. RawBuffer e -&gt; Int -&gt; Ptr e -&gt; Int -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#copyToRawBuffer"><span class="hs-identifier hs-var hs-var">copyToRawBuffer</span></a></span></span><span> </span><span id="local-6989586621679556549"><span class="annot"><span class="annottext">RawBuffer e
</span><a href="#local-6989586621679556549"><span class="hs-identifier hs-var">raw</span></a></span></span><span> </span><span id="local-6989586621679556548"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556548"><span class="hs-identifier hs-var">off</span></a></span></span><span> </span><span id="local-6989586621679556547"><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679556547"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679556546"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556546"><span class="hs-identifier hs-var">bytes</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1138"></span><span> </span><span class="annot"><span class="annottext">RawBuffer e -&gt; (Ptr e -&gt; IO ()) -&gt; IO ()
forall e a. RawBuffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Buffer.html#withRawBuffer"><span class="hs-identifier hs-var">withRawBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer e
</span><a href="#local-6989586621679556549"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr e -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr e -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679556545"><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679556545"><span class="hs-identifier hs-var">praw</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-1139"></span><span>   </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">Ptr ()
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr e -&gt; Ptr e -&gt; CSize -&gt; IO (Ptr ())
forall a. Ptr a -&gt; Ptr a -&gt; CSize -&gt; IO (Ptr ())
</span><a href="GHC.IO.Handle.Text.html#memcpy"><span class="hs-identifier hs-var">memcpy</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679556545"><span class="hs-identifier hs-var">praw</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr e -&gt; Int -&gt; Ptr e
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556548"><span class="hs-identifier hs-var">off</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679556547"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CSize
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556546"><span class="hs-identifier hs-var">bytes</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1140"></span><span>      </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-1141"></span><span>
</span><span id="line-1142"></span><span id="local-6989586621679557942"><span class="annot"><a href="GHC.IO.Handle.Text.html#copyFromRawBuffer"><span class="hs-identifier hs-type">copyFromRawBuffer</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679557942"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.IO.Buffer.html#RawBuffer"><span class="hs-identifier hs-type">RawBuffer</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679557942"><span class="hs-identifier hs-type">e</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span></span><span>
</span><span id="line-1143"></span><span id="copyFromRawBuffer"><span class="annot"><span class="annottext">copyFromRawBuffer :: forall e. Ptr e -&gt; RawBuffer e -&gt; Int -&gt; Int -&gt; IO ()
</span><a href="GHC.IO.Handle.Text.html#copyFromRawBuffer"><span class="hs-identifier hs-var hs-var">copyFromRawBuffer</span></a></span></span><span> </span><span id="local-6989586621679556540"><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679556540"><span class="hs-identifier hs-var">ptr</span></a></span></span><span> </span><span id="local-6989586621679556539"><span class="annot"><span class="annottext">RawBuffer e
</span><a href="#local-6989586621679556539"><span class="hs-identifier hs-var">raw</span></a></span></span><span> </span><span id="local-6989586621679556538"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556538"><span class="hs-identifier hs-var">off</span></a></span></span><span> </span><span id="local-6989586621679556537"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556537"><span class="hs-identifier hs-var">bytes</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1144"></span><span> </span><span class="annot"><span class="annottext">RawBuffer e -&gt; (Ptr e -&gt; IO ()) -&gt; IO ()
forall e a. RawBuffer e -&gt; (Ptr e -&gt; IO a) -&gt; IO a
</span><a href="GHC.IO.Buffer.html#withRawBuffer"><span class="hs-identifier hs-var">withRawBuffer</span></a></span><span> </span><span class="annot"><span class="annottext">RawBuffer e
</span><a href="#local-6989586621679556539"><span class="hs-identifier hs-var">raw</span></a></span><span> </span><span class="annot"><span class="annottext">((Ptr e -&gt; IO ()) -&gt; IO ()) -&gt; (Ptr e -&gt; IO ()) -&gt; IO ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="hs-glyph">\</span><span id="local-6989586621679556536"><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679556536"><span class="hs-identifier hs-var">praw</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span>
</span><span id="line-1145"></span><span>   </span><span class="hs-keyword">do</span><span> </span><span class="annot"><span class="annottext">Ptr ()
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ptr e -&gt; Ptr e -&gt; CSize -&gt; IO (Ptr ())
forall a. Ptr a -&gt; Ptr a -&gt; CSize -&gt; IO (Ptr ())
</span><a href="GHC.IO.Handle.Text.html#memcpy"><span class="hs-identifier hs-var">memcpy</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679556540"><span class="hs-identifier hs-var">ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ptr e
</span><a href="#local-6989586621679556536"><span class="hs-identifier hs-var">praw</span></a></span><span> </span><span class="annot"><span class="annottext">Ptr e -&gt; Int -&gt; Ptr e
forall a b. Ptr a -&gt; Int -&gt; Ptr b
</span><a href="GHC.Ptr.html#plusPtr"><span class="hs-operator hs-var">`plusPtr`</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556538"><span class="hs-identifier hs-var">off</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Int -&gt; CSize
forall a b. (Integral a, Num b) =&gt; a -&gt; b
</span><a href="GHC.Real.html#fromIntegral"><span class="hs-identifier hs-var">fromIntegral</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556537"><span class="hs-identifier hs-var">bytes</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1146"></span><span>      </span><span class="annot"><span class="annottext">() -&gt; IO ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span>
</span><span id="line-1147"></span><span>
</span><span id="line-1148"></span><span id="local-6989586621679557913"><span class="hs-keyword">foreign</span><span> </span><span class="hs-keyword">import</span><span> </span><span class="annot"><span class="hs-keyword">ccall</span></span><span> </span><span class="annot"><span class="hs-keyword">unsafe</span></span><span> </span><span class="annot"><span class="hs-string">&quot;memcpy&quot;</span></span><span>
</span><span id="line-1149"></span><span>   </span><span id="memcpy"><span class="annot"><a href="GHC.IO.Handle.Text.html#memcpy"><span class="hs-identifier hs-var">memcpy</span></a></span></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679557913"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679557913"><span class="hs-identifier hs-type">a</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="Foreign.C.Types.html#CSize"><span class="hs-identifier hs-type">CSize</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Ptr.html#Ptr"><span class="hs-identifier hs-type">Ptr</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span class="hs-special">)</span></span><span>
</span><span id="line-1150"></span><span>
</span><span id="line-1151"></span><span class="hs-comment">-----------------------------------------------------------------------------</span><span>
</span><span id="line-1152"></span><span class="hs-comment">-- Internal Utils</span><span>
</span><span id="line-1153"></span><span>
</span><span id="line-1154"></span><span id="local-6989586621679557973"><span class="annot"><a href="GHC.IO.Handle.Text.html#illegalBufferSize"><span class="hs-identifier hs-type">illegalBufferSize</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.IO.Handle.Types.html#Handle"><span class="hs-identifier hs-type">Handle</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Base.html#String"><span class="hs-identifier hs-type">String</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#Int"><span class="hs-identifier hs-type">Int</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="../../ghc-prim/src/GHC.Types.html#IO"><span class="hs-identifier hs-type">IO</span></a></span><span> </span><span class="annot"><a href="#local-6989586621679557973"><span class="hs-identifier hs-type">a</span></a></span></span><span>
</span><span id="line-1155"></span><span id="illegalBufferSize"><span class="annot"><span class="annottext">illegalBufferSize :: forall a. Handle -&gt; String -&gt; Int -&gt; IO a
</span><a href="GHC.IO.Handle.Text.html#illegalBufferSize"><span class="hs-identifier hs-var hs-var">illegalBufferSize</span></a></span></span><span> </span><span id="local-6989586621679556534"><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679556534"><span class="hs-identifier hs-var">handle</span></a></span></span><span> </span><span id="local-6989586621679556533"><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679556533"><span class="hs-identifier hs-var">fn</span></a></span></span><span> </span><span id="local-6989586621679556532"><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556532"><span class="hs-identifier hs-var">sz</span></a></span></span><span> </span><span class="hs-glyph">=</span><span>
</span><span id="line-1156"></span><span>        </span><span class="annot"><span class="annottext">IOError -&gt; IO a
forall a. IOError -&gt; IO a
</span><a href="GHC.IO.Exception.html#ioException"><span class="hs-identifier hs-var">ioException</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Maybe Handle
-&gt; IOErrorType
-&gt; String
-&gt; String
-&gt; Maybe CInt
-&gt; Maybe String
-&gt; IOError
</span><a href="GHC.IO.Exception.html#IOError"><span class="hs-identifier hs-var">IOError</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Handle -&gt; Maybe Handle
forall a. a -&gt; Maybe a
</span><a href="GHC.Maybe.html#Just"><span class="hs-identifier hs-var">Just</span></a></span><span> </span><span class="annot"><span class="annottext">Handle
</span><a href="#local-6989586621679556534"><span class="hs-identifier hs-var">handle</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1157"></span><span>                            </span><span class="annot"><span class="annottext">IOErrorType
</span><a href="GHC.IO.Exception.html#InvalidArgument"><span class="hs-identifier hs-var">InvalidArgument</span></a></span><span>  </span><span class="annot"><span class="annottext">String
</span><a href="#local-6989586621679556533"><span class="hs-identifier hs-var">fn</span></a></span><span>
</span><span id="line-1158"></span><span>                            </span><span class="hs-special">(</span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;illegal buffer size &quot;</span></span><span> </span><span class="annot"><span class="annottext">String -&gt; String -&gt; String
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">Int -&gt; Int -&gt; String -&gt; String
forall a. Show a =&gt; Int -&gt; a -&gt; String -&gt; String
</span><a href="GHC.Show.html#showsPrec"><span class="hs-identifier hs-var">showsPrec</span></a></span><span> </span><span class="annot"><span class="annottext">Int
</span><span class="hs-number">9</span></span><span> </span><span class="annot"><span class="annottext">Int
</span><a href="#local-6989586621679556532"><span class="hs-identifier hs-var">sz</span></a></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-1159"></span><span>                            </span><span class="annot"><span class="annottext">Maybe CInt
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe String
forall a. Maybe a
</span><a href="GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-1160"></span><span>
</span><span id="line-1161"></span></pre></body></html>